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,6 +213,48 @@ class EnhancedTable extends Component {
|
||||||
|
|
||||||
isSelected = id => this.state.selected.indexOf(id) !== -1;
|
isSelected = id => this.state.selected.indexOf(id) !== -1;
|
||||||
|
|
||||||
|
filterData(data, searchQuery, searchColumns) {
|
||||||
|
// Remove white spaces and wrong "" split
|
||||||
|
const queryTerms = searchQuery.split(' ').filter(value => value !== '');
|
||||||
|
|
||||||
|
return data.filter((item) => {
|
||||||
|
|
||||||
|
const insertArray = [];
|
||||||
|
// Implement hardcoded AND query over each column
|
||||||
|
// Iterate over each search term
|
||||||
|
queryTerms.forEach(searchItem => {
|
||||||
|
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(searchItem.toLowerCase().trim()) !== -1
|
||||||
|
){
|
||||||
|
insert = true;
|
||||||
|
}
|
||||||
|
else if(item[column.name].toLowerCase().indexOf(searchItem.toLowerCase().trim()) !== -1){
|
||||||
|
insert = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(error) {
|
||||||
|
//console.error(error);
|
||||||
|
}
|
||||||
|
return column;
|
||||||
|
});
|
||||||
|
|
||||||
|
insertArray.push(insert);
|
||||||
|
});
|
||||||
|
|
||||||
|
// AND logic
|
||||||
|
if(insertArray.filter(item => !item).length === 0){
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { data } = this.props;
|
let { data } = this.props;
|
||||||
const { columnData, rowsPerPageOptions, showSearchColumns } = this.props;
|
const { columnData, rowsPerPageOptions, showSearchColumns } = this.props;
|
||||||
|
@ -246,46 +262,7 @@ class EnhancedTable extends Component {
|
||||||
|
|
||||||
// Logic of search query and columns
|
// Logic of search query and columns
|
||||||
if(searchQuery.length > 0) {
|
if(searchQuery.length > 0) {
|
||||||
|
data = this.filterData(data, searchQuery, searchColumns);
|
||||||
// Remove white spaces and wrong "" split
|
|
||||||
const queryTerms = searchQuery.split(' ').filter(value => value !== '');
|
|
||||||
|
|
||||||
data = data.filter((item) => {
|
|
||||||
|
|
||||||
const insertArray = [];
|
|
||||||
// Implement hardcoded AND query over each column
|
|
||||||
// Iterate over each search term
|
|
||||||
queryTerms.forEach(searchItem => {
|
|
||||||
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(searchItem.toLowerCase().trim()) !== -1
|
|
||||||
){
|
|
||||||
insert = true;
|
|
||||||
}
|
|
||||||
else if(item[column.name].toLowerCase().indexOf(searchItem.toLowerCase().trim()) !== -1){
|
|
||||||
insert = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(error) {
|
|
||||||
//console.error(error);
|
|
||||||
}
|
|
||||||
return column;
|
|
||||||
});
|
|
||||||
|
|
||||||
insertArray.push(insert);
|
|
||||||
});
|
|
||||||
|
|
||||||
// AND logic
|
|
||||||
if(insertArray.filter(item => !item).length === 0){
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data = this.sortData(data);
|
data = this.sortData(data);
|
||||||
|
|
Loading…
Reference in a new issue