-1

I've tried this: Angular + Material - How To Refresh A Data Source (mat-table) and it works, too well, actually!

I want to filter OUT a value and show all others, but this is doing the reverse.

applyFilter("INACTIVE"); <-- This only "SHOWS", of course, all INACTIVE records, but I want the opposite.


applyFilter(filterValue: string) {
  filterValue = filterValue.trim();
  //filterValue = filterValue.toLowerCase();
  this.applicationList.filter = filterValue;
}

refresh() {
  this.changeDetectorRefs.detectChanges();
}

The values I want to show are: IN_PROGRESS, ACTIVE, NEW and the only value I do not want to show is: INACTIVE.

When I call this applyFilter() function, I use the arguement: "INACTIVE" but the result is "ONLY INACTIVE" records... but I want the opposite: Not SHOW the INACTIVE but everything else.

Thank you

Peter The Angular Dude
  • 1,112
  • 5
  • 26
  • 53
  • The documentation (https://material.angular.io/components/table/api#MatTableDataSource) says: *To override how data objects match to this filter string, provide a custom function for filterPredicate.* – JB Nizet Jun 08 '18 at 17:25
  • So, how do I input, as an argument, IN_PROGRESS, SIGNED, ACTIVE while not showing "INACTIVE"? This link is vague. – Peter The Angular Dude Jun 08 '18 at 17:50

1 Answers1

1

Just do the opposite in your function .

Since when you use filter function , it returns the filtered objects.. for example

let us assume you have an array of objects like this

array = [ { id : 1, name : 'name1', address : 'usa' }, { id : 2, name : 'name2', address : 'canada' }, { id : 3, name : 'name3', address : 'australia' } ];

to get everything except user with id 2 you can do something like this

array = array.filter( x => x.name !== 'name2' );

This will return for you the array , without name2.

I Hope this is what you were looking for