Fix filtered data to external update query event

This commit is contained in:
Letícia Camara 2019-01-21 00:09:52 -02:00
parent 4df858b4f0
commit bd40a19942

View file

@ -169,33 +169,7 @@ class EnhancedTable extends Component {
const searchQuery = query;
const searchColumns = this.state.searchColumns;
const data = this.props.data.filter((item) => {
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;
});
const data = this.filterData(this.props.data, searchQuery, searchColumns);
this.props.onSearchChange(data);
};
@ -239,18 +213,11 @@ class EnhancedTable extends Component {
isSelected = id => this.state.selected.indexOf(id) !== -1;
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) {
filterData(data, searchQuery, searchColumns) {
// Remove white spaces and wrong "" split
const queryTerms = searchQuery.split(' ').filter(value => value !== '');
data = data.filter((item) => {
return data.filter((item) => {
const insertArray = [];
// 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);
return (