@@ -174,11 +174,10 @@ export class DataTable extends React.Component {
174174 getDisplayedColumns ( data ) {
175175 const flatPaths = getSurveyFlatPaths ( this . props . asset . content . survey ) ;
176176
177- // start with all paths
177+ // add all questions from the survey definition
178178 let output = Object . values ( flatPaths ) ;
179179
180- // makes sure the survey columns are displayed, even if current data's
181- // submissions doesn't have them
180+ // Gather unique columns from all visible submissions and add them to output
182181 const dataKeys = Object . keys ( data . reduce ( function ( result , obj ) {
183182 return Object . assign ( result , obj ) ;
184183 } , { } ) ) ;
@@ -194,18 +193,25 @@ export class DataTable extends React.Component {
194193 const foundPathKey = Object . keys ( flatPaths ) . find ( ( pathKey ) => {
195194 return flatPaths [ pathKey ] === key ;
196195 } ) ;
197- const foundRow = this . props . asset . content . survey . find ( ( row ) => {
196+
197+ // no path means this definitely is not a note type
198+ if ( ! foundPathKey ) {
199+ return true ;
200+ }
201+
202+ const foundNoteRow = this . props . asset . content . survey . find ( ( row ) => {
198203 return (
199- key === row . name ||
200- key === row . $autoname ||
201- foundPathKey === row . name ||
202- foundPathKey === row . $autoname
204+ typeof foundPathKey !== 'undefined' &&
205+ ( foundPathKey === row . name || foundPathKey === row . $autoname ) &&
206+ row . type === QUESTION_TYPES . get ( 'note' ) . id
203207 ) ;
204208 } ) ;
205- if ( foundRow ) {
206- return foundRow . type !== QUESTION_TYPES . get ( 'note' ) . id ;
209+ if ( typeof foundNoteRow !== 'undefined' ) {
210+ // filter out this row as this is a note type
211+ return false ;
207212 }
208- return false ;
213+
214+ return true ;
209215 } ) ;
210216
211217 // exclude kobomatrix rows as data is not directly tied to them, but
0 commit comments