Fix filtered data to external update query event
This commit is contained in:
parent
4df858b4f0
commit
bd40a19942
1 changed files with 44 additions and 67 deletions
|
@ -169,33 +169,7 @@ class EnhancedTable extends Component {
|
||||||
|
|
||||||
const searchQuery = query;
|
const searchQuery = query;
|
||||||
const searchColumns = this.state.searchColumns;
|
const searchColumns = this.state.searchColumns;
|
||||||
const data = this.props.data.filter((item) => {
|
const data = this.filterData(this.props.data, searchQuery, searchColumns);
|
||||||
let insert = false;
|
|
||||||
|
|
||||||
// Iterate over the search column select boxes
|
|
||||||
searchColumns.map(column => {
|
|
||||||
try {
|
|
||||||
if( column.checked && (item[column.name] !== undefined) ) {
|
|
||||||
|
|
||||||
if(item[column.name].hasOwnProperty('searchText') && item[column.name].searchText.toLowerCase().indexOf(searchQuery.toLowerCase().trim()) !== -1){
|
|
||||||
insert = true;
|
|
||||||
}
|
|
||||||
else if(item[column.name].toLowerCase().indexOf(searchQuery.toLowerCase().trim()) !== -1){
|
|
||||||
insert = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(error) {
|
|
||||||
//console.error(error);
|
|
||||||
}
|
|
||||||
return column;
|
|
||||||
});
|
|
||||||
|
|
||||||
if(insert){
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.props.onSearchChange(data);
|
this.props.onSearchChange(data);
|
||||||
};
|
};
|
||||||
|
@ -239,18 +213,11 @@ class EnhancedTable extends Component {
|
||||||
|
|
||||||
isSelected = id => this.state.selected.indexOf(id) !== -1;
|
isSelected = id => this.state.selected.indexOf(id) !== -1;
|
||||||
|
|
||||||
render() {
|
filterData(data, searchQuery, searchColumns) {
|
||||||
let { data } = this.props;
|
|
||||||
const { columnData, rowsPerPageOptions, showSearchColumns } = this.props;
|
|
||||||
const { order, orderBy, selected, rowsPerPage, page, searchQuery, searchColumns } = this.state;
|
|
||||||
|
|
||||||
// Logic of search query and columns
|
|
||||||
if(searchQuery.length > 0) {
|
|
||||||
|
|
||||||
// Remove white spaces and wrong "" split
|
// Remove white spaces and wrong "" split
|
||||||
const queryTerms = searchQuery.split(' ').filter(value => value !== '');
|
const queryTerms = searchQuery.split(' ').filter(value => value !== '');
|
||||||
|
|
||||||
data = data.filter((item) => {
|
return data.filter((item) => {
|
||||||
|
|
||||||
const insertArray = [];
|
const insertArray = [];
|
||||||
// Implement hardcoded AND query over each column
|
// Implement hardcoded AND query over each column
|
||||||
|
@ -288,6 +255,16 @@ class EnhancedTable extends Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
let { data } = this.props;
|
||||||
|
const { columnData, rowsPerPageOptions, showSearchColumns } = this.props;
|
||||||
|
const { order, orderBy, selected, rowsPerPage, page, searchQuery, searchColumns } = this.state;
|
||||||
|
|
||||||
|
// Logic of search query and columns
|
||||||
|
if(searchQuery.length > 0) {
|
||||||
|
data = this.filterData(data, searchQuery, searchColumns);
|
||||||
|
}
|
||||||
|
|
||||||
data = this.sortData(data);
|
data = this.sortData(data);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue