2

I understand we can use a Standalone filter without individual column filters (https://akveo.github.io/ng2-smart-table/#/examples/using-filters) But is it possible to use both?

I tried to implement it but could not. See https://stackblitz.com/edit/angular-2cwakj?file=src%2Fapp%2Ffilter-poc%2Ffilter-poc.component.ts

1 Answers1

2

Change your onSearch function with following function.

  onSearch(query: string = '') {
   this.source = new LocalDataSource(this.data.filter((obj)=>{
   if(obj.id.toString().indexOf(query)>-1 || obj.name.indexOf(query)>-1 || 
    obj.username.indexOf(query)>-1 ||obj.email.indexOf(query)>-1 ) return true;
   else false;
  }))
 }
sacgro
  • 459
  • 2
  • 5
  • thanks, this works for the global filter. But is there a way we can combine both global and individual filters? I have updated the code at https://stackblitz.com/edit/angular-2cwakj?file=src%2Fapp%2Ffilter-poc%2Ffilter-poc.component.ts – Solomon Sahayaraj Feb 17 '20 at 08:25
  • What do you mean by combining.. Explain with example – sacgro Feb 17 '20 at 09:38
  • Example: check the code here [link] (https://stackblitz.com/edit/angular-2cwakj?file=src%2Fapp%2Ffilter-poc%2Ffilter-poc.component.ts) 1st use the column filter in the Email column for "Combined" . 2 rows will return. after that, use the global filter to search for "Bret". It should return 1 row but it returns 2 rows since the column filter is getting reset – Solomon Sahayaraj Feb 17 '20 at 10:43
  • 1
    It will work if you enter global filter first and then column filter... because when we add something in global filter it will reset column filters – sacgro Feb 17 '20 at 11:56