Skip to content

Commit

Permalink
Merge pull request #2167 from kobotoolbox/2153-table-header-sort-fix
Browse files Browse the repository at this point in the history
Fix disappearing columns for no data
  • Loading branch information
jnm authored Jan 28, 2019
2 parents dc3c710 + 7d6e6df commit c735297
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions jsapp/js/components/table.es6
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,36 @@ export class DataTable extends React.Component {
console.error(error);
});
}

_prepColumns(data) {
var excludes = ['_xform_id_string', '_attachments', '_notes', '_bamboo_dataset_id', '_status',
'formhub/uuid', '_tags', '_geolocation', '_submitted_by', 'meta/instanceID', 'meta/deprecatedID', '_validation_status'];
const excludedKeys = [
'_xform_id_string',
'_attachments',
'_notes',
'_bamboo_dataset_id',
'_status',
'formhub/uuid',
'_tags',
'_geolocation',
'_submitted_by',
'meta/instanceID',
'meta/deprecatedID',
'_validation_status'
];

var uniqueKeys = Object.keys(data.reduce(function(result, obj) {
const dataKeys = Object.keys(data.reduce(function(result, obj) {
return Object.assign(result, obj);
}, {}));

uniqueKeys = uniqueKeys.filter((el, ind, arr) => excludes.includes(el) === false);
const surveyKeys = [];
this.props.asset.content.survey.forEach((row) => {
surveyKeys.push(row.$autoname);
});

// make sure the survey columns are displayed, even if current data's
// submissions doesn't have them
let uniqueKeys = [...new Set([...dataKeys, ...surveyKeys])];
uniqueKeys = uniqueKeys.filter((key) => excludedKeys.includes(key) === false);

let showLabels = this.state.showLabels,
showGroupName = this.state.showGroupName,
Expand Down

0 comments on commit c735297

Please sign in to comment.