I've been trying to get this working with no luck. I've been referencing these resources for help:
http://swimlane.github.io/ngx-datatable/#filter
https://github.com/swimlane/ngx-datatable/blob/master/demo/basic/filter.component.ts
Basically i just want to allow my filter to apply to more than a single column, without implementing code to handle every column. (Some datatables have 20+ columns!)
Example Code:
//HTML
<input type='text' placeholder='Filter' (keyup)='updateFilter($event.target.value)' />
<ngx-datatable
class="material"
columnMode="force"
[columns]="gridProperties.FilteredColumns"
[footerHeight]="50"
[loadingIndicator]="gridLoadingIndicator"
[rows]="filteredList"
[scrollbarH]="false"
[scrollbarV]="true"
[selected]="selectedItem"
[selectionType]="'single'"
style="min-height:400px;">
</ngx-datatable>
//TYPESCRIPT
public items: Item[];
updateFilter(filterValue) {
const lowerValue = filterValue.toLowerCase();
this.filteredList = this.items.filter(item => item.name.toLowerCase().indexOf(lowerValue) !== -1 || !lowerValue);
}
Here I am obviously just handling filtering for the 'name' property of my items array. This works great as is, but like I had mentioned, if the grid contains many columns I'd like one method to handle all of them. Any help or tips are appreciated.
While storing the data in rows list at that time also initilize perttemp list, so that we can fetch after filter
updateFilter(event) {
const val = event.target.value.toLowerCase();
if(val) {
this.temp = this.rows;
// filter our data
const temp = this.temp.filter(function (d) {
return ( d.name.toLowerCase().indexOf(val) !== -1 || d.email.toLowerCase().indexOf(val) !== -1 || !val);
});
this.rows = temp;
}
else
{
this.rows = this.perttemp;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With