-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(table): broaden abstraction for filtering #8059
fix(table): broaden abstraction for filtering #8059
Conversation
src/lib/table/table-data-source.ts
Outdated
*/ | ||
filterTermAccessor: ((data: T) => string) = (data: T): string => { | ||
filterMatcher: ((data: T, filter: string) => boolean) = (data: T, filter: string): boolean => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filterPredicate
?
src/lib/table/table-data-source.ts
Outdated
const accumulator = (currentTerm, key) => currentTerm + data[key]; | ||
return Object.keys(data).reduce(accumulator, '').toLowerCase(); | ||
const dataStr = Object.keys(data).reduce(accumulator, '').toLowerCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to filter on the keys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it, but its actually iterating over each of the object's keys and then reducing it via the accumulator function. That function takes each key and accesses the data's property and appends it to the accumulated value.
In the end an object like {name: 'John', color: 'Blue', age: '27'}
ends up looking like 'JohnBlue27'
Would be nice to use Object.values()
but its not supported by IE
Renamed the filter function to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/lib/table/table-data-source.ts
Outdated
* Checks if a data object matches the data source's filter string. By default, each data object | ||
* is converted to a string of its properties and returns true if the filter has | ||
* at least one occurrence in that string. By default, the filter string has its whitespace | ||
* removed and the match is case-insensitive. May be overriden for a custom implementation of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"...has its whitespace trimmed and the match..."?
To me, "removed" kind of implies that { name: "Mr. Smith" }
would end up as mr.smith
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I can see how that could be taken both ways
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Currently the user can customize the
MatTableDataSource
's filtering by providing a custom function of how to convert a data object into a filter string.This may be too in-depth for most users and not as intuitive.
This PR broadens the abstraction so that users instead will define a function that accepts data and a filter string, and returns true/false depending on if the data matches.
This also allows the data source some freedom in defaulting to a behavior where it trims/lowercases the filter but allows users to override that behavior easily.