Skip to content

Commit

Permalink
main - c12b73e fix(material/table): improve filter predicate efficien…
Browse files Browse the repository at this point in the history
…cy (#30172)
  • Loading branch information
andrewseguin committed Dec 12, 2024
1 parent b5aa289 commit efcb406
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
15 changes: 2 additions & 13 deletions fesm2022/table.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -694,21 +694,10 @@ class MatTableDataSource extends DataSource {
* @returns Whether the filter matches against the data
*/
filterPredicate = (data, filter) => {
// Transform the data into a lowercase string of all property values.
const dataStr = Object.keys(data)
.reduce((currentTerm, key) => {
// Use an obscure Unicode character to delimit the words in the concatenated string.
// This avoids matches where the values of two columns combined will match the user's query
// (e.g. `Flute` and `Stop` will match `Test`). The character is intended to be something
// that has a very low chance of being typed in by somebody in a text field. This one in
// particular is "White up-pointing triangle with dot" from
// https://en.wikipedia.org/wiki/List_of_Unicode_characters
return currentTerm + data[key] + '◬';
}, '')
.toLowerCase();
// Transform the filter by converting it to lowercase and removing whitespace.
const transformedFilter = filter.trim().toLowerCase();
return dataStr.indexOf(transformedFilter) != -1;
// Loops over the values in the array and returns true if any of them match the filter string
return Object.values(data).some(value => `${value}`.toLowerCase().includes(transformedFilter));
};
constructor(initialData = []) {
super();
Expand Down
Loading

0 comments on commit efcb406

Please sign in to comment.