question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Table] MatTableDataSource does not execute filter predicate if filter evaluates to false

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Filter text should not be required for using a filter when a custom filterPredicate is supplied

What is the current behavior?

Filter text must be truthy in order to use a filterPredicate which does not require filter text

What are the steps to reproduce?

Make a filterPredicate which does not depend on the filter value

What is the use-case or motivation for changing an existing behavior?

Filter predicates which do not require the filter text (for example, checking that a value in the data is past the current date)

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Current

Is there anything else we should know?

https://github.com/angular/material2/blob/master/src/lib/table/table-data-source.ts#L213 !this.filter ? data : data.filter(obj => this.filterPredicate(obj, this.filter)); Instead of !this.filter ? check if a filterPredicate has been supplied

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
RomainSanchezcommented, Jul 25, 2019

@Eddygn

when making a custom predicate, if it’s not dependent on the filter string but instead on external flags and the row data, there is no way to trigger the filter itself except to pass some new string to the filter text, even if it’s meaningless. So for now ‘stringifying’ those flags looks like the best option even if the string is not used. I think it will be great if there is a method to call to filter, bypassing the filter change detection, or triggering it manually.

i worked around it this way (ugly)

const currentFilter = this.tableDataSource.filter;

this.tableDataSource.filter = '------';
this.tableDataSource.filter = currentFilter;

3reactions
Eddygncommented, Feb 16, 2018

Somewhat related, when making a custom predicate, if it’s not dependent on the filter string but instead on external flags and the row data, there is no way to trigger the filter itself except to pass some new string to the filter text, even if it’s meaningless. So for now ‘stringifying’ those flags looks like the best option even if the string is not used. I think it will be great if there is a method to call to filter, bypassing the filter change detection, or triggering it manually.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Material table filterPredicate not invoked
I got this working my moving the filter to where I added the subscription this.subs.add(this.
Read more >
Working with mat-table filterPredicate in Angular
mat-table data source filterPredicate function filters the table rows based on the filter string passed to the MatTableDataSource. By default filterPredicate ...
Read more >
Angular Material Mat-Table Not Returning Any Results Upon ...
If you want to use filter only specific columns you need to override ... [Table] MatTableDataSource does not execute filter predicate if filter...
Read more >
Table | Angular Material
The filtered set of data that has been matched by the filter string, or all the data if there is no filter. Useful...
Read more >
ReQL command: filter - RethinkDB
If default is set to false (the default), documents with missing fields ... Predicates to filter are evaluated on the server, and must...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found