Skip to content

Commit

Permalink
Merge pull request #1993 from kobotoolbox/issue-1918
Browse files Browse the repository at this point in the history
More table view column filters
  • Loading branch information
pmusaraj authored Sep 22, 2018
2 parents ba0257b + 08dcc47 commit 98affdb
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions jsapp/js/components/table.es6
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ export class DataTable extends React.Component {
if (filter.length) {
filterQuery = '&query={';
filter.forEach(function(f, i) {
filterQuery += `"${f.id}":{"$regex":"${f.value}"}`;
if (f.id === '_id') {
filterQuery += `"${f.id}":{"$in":[${f.value}]}`;
} else {
filterQuery += `"${f.id}":{"$regex":"${f.value}","$options":"i"}`;
}
if (i < filter.length - 1)
filterQuery += ',';
});
Expand Down Expand Up @@ -108,7 +112,7 @@ export class DataTable extends React.Component {
loading: false
});
// TODO: debounce the queries and then enable this notification
notify(t('The query did not return any results.'));
alertify.warning(t('The query did not return any results.'));
} else {
this.setState({error: t('Error: could not load data.'), loading: false});
}
Expand Down Expand Up @@ -401,8 +405,30 @@ export class DataTable extends React.Component {
})

let selectedColumns = false,
frozenColumn = false,
textFilterQuestionTypes = ['text', 'integer', 'decimal'];
frozenColumn = false;
const textFilterQuestionTypes = [
'text',
'integer',
'decimal',
'select_multiple',
'date',
'time',
'datetime',
'start',
'end',
'username',
'simserial',
'subscriberid',
'deviceid',
'phonenumber',
'today'
];
const textFilterQuestionIds = [
'__version__',
'_id',
'_uuid',
'_submission_time'
]

if (settings['data-table'] && settings['data-table']['frozen-column']) {
frozenColumn = settings['data-table']['frozen-column'];
Expand All @@ -424,10 +450,14 @@ export class DataTable extends React.Component {
})}
</select>;
}
if (col.question && textFilterQuestionTypes.includes(col.question.type)) {
if (
(col.question && textFilterQuestionTypes.includes(col.question.type))
|| textFilterQuestionIds.includes(col.id)
) {
col.filterable = true;
col.Filter = ({ filter, onChange }) =>
<DebounceInput
value={filter ? filter.value : undefined}
debounceTimeout={750}
onChange={event => onChange(event.target.value)}
style={{ width: '100%' }}/>;
Expand Down

0 comments on commit 98affdb

Please sign in to comment.