Skip to content

Commit

Permalink
fix search results table column filtering again, fixes #244
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten König committed Dec 5, 2024
1 parent 5574567 commit e4a6268
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.1.1

* truncate long fields in search results table, fixes [#211](https://github.com/cars10/elasticvue/issues/211)
* fix search results table column filtering again, fixes [#244](https://github.com/cars10/elasticvue/issues/244)

## 1.1.0

Expand Down
20 changes: 16 additions & 4 deletions src/helpers/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,33 @@ export function filterItems<T extends Filterable> (items: T[], searchQuery: stri
if (column.trim() === '') return items

return items.filter(item => {
if (Object.hasOwnProperty.bind(item)(column) && item[column] !== null) {
return item[column].toString().toLowerCase().includes(query)
if (columnFilterable(item, column)) {
return filterColumn(item, column, query)
}
})
} else {
return items.filter(item => {
return headerNames.some(headerName => {
if (Object.hasOwnProperty.bind(item)(headerName) && item[headerName] !== null) {
return item[headerName].toString().toLowerCase().includes(search)
if (columnFilterable(item, headerName)) {
return filterColumn(item, headerName, search)
}
})
})
}
}

const columnFilterable = (item: any, headerName: string) =>{
return Object.hasOwnProperty.bind(item)(headerName) && item[headerName] !== null
}

const filterColumn = (item: any, headerName: string, search: string) => {
try {
return item[headerName].toString().toLowerCase().includes(search)
} catch(e) {
return false
}
}

const filterSpecificColumn = (searchSplit: string[], headerNames: string[]): boolean => {
return searchSplit.length > 1 && headerNames.includes(searchSplit[0])
}

0 comments on commit e4a6268

Please sign in to comment.