Extend search algorith to include AND between columns and sort at EnhacedTable component
This commit is contained in:
parent
26357612eb
commit
7a17666e76
3 changed files with 21 additions and 8 deletions
|
@ -219,18 +219,27 @@ 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 = data.filter((item) => {
|
|
||||||
let insert = false;
|
|
||||||
|
|
||||||
|
// 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
|
// Iterate over the search column select boxes
|
||||||
searchColumns.map(column => {
|
searchColumns.map(column => {
|
||||||
try {
|
try {
|
||||||
if( column.checked && (item[column.name] !== undefined) ) {
|
if( column.checked && (item[column.name] !== undefined) ) {
|
||||||
|
if(item[column.name].hasOwnProperty('searchText') &&
|
||||||
if(item[column.name].hasOwnProperty('searchText') && item[column.name].searchText.toLowerCase().indexOf(searchQuery.toLowerCase().trim()) !== -1){
|
item[column.name].searchText.toLowerCase().indexOf(searchItem.toLowerCase().trim()) !== -1
|
||||||
|
){
|
||||||
insert = true;
|
insert = true;
|
||||||
}
|
}
|
||||||
else if(item[column.name].toLowerCase().indexOf(searchQuery.toLowerCase().trim()) !== -1){
|
else if(item[column.name].toLowerCase().indexOf(searchItem.toLowerCase().trim()) !== -1){
|
||||||
insert = true;
|
insert = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,7 +250,11 @@ class EnhancedTable extends Component {
|
||||||
return column;
|
return column;
|
||||||
});
|
});
|
||||||
|
|
||||||
if(insert){
|
insertArray.push(insert);
|
||||||
|
});
|
||||||
|
|
||||||
|
// AND logic
|
||||||
|
if(insertArray.filter(item => !item).length === 0){
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -357,7 +357,7 @@ class AmbassadorsPage extends Component {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
data = data.sort(sortBy('location.searchText'));
|
data = data.sort(sortBy('nickname'));
|
||||||
|
|
||||||
const textComponent = (
|
const textComponent = (
|
||||||
<span>
|
<span>
|
||||||
|
|
|
@ -419,7 +419,7 @@ class MerchantsPage extends Component {
|
||||||
return this.getMerchantMarker(merchant);
|
return this.getMerchantMarker(merchant);
|
||||||
});
|
});
|
||||||
|
|
||||||
merchantsData = merchantsData.sort(sortBy('location.searchText'));
|
merchantsData = merchantsData.sort(sortBy('name'));
|
||||||
|
|
||||||
const textComponent = (
|
const textComponent = (
|
||||||
<span>
|
<span>
|
||||||
|
|
Loading…
Reference in a new issue