From 9bb59f3ad5fdc30b1432065a2dc06f9a5e3e9685 Mon Sep 17 00:00:00 2001 From: Daniel Brenot Date: Tue, 15 Dec 2020 16:43:39 -0500 Subject: [PATCH] chore: modified table predicate filter --- src/material/table/table-data-source.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/material/table/table-data-source.ts b/src/material/table/table-data-source.ts index af29105cec4a..6e3787b11314 100644 --- a/src/material/table/table-data-source.ts +++ b/src/material/table/table-data-source.ts @@ -188,21 +188,12 @@ export class _MatTableDataSource extends DataSource { * @returns Whether the filter matches against the data */ filterPredicate: ((data: T, filter: string) => boolean) = (data: T, filter: string): boolean => { - // Transform the data into a lowercase string of all property values. - const dataStr = Object.keys(data).reduce((currentTerm: string, key: string) => { - // 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 as {[key: string]: any})[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.keys(data).some( + (key)=>(data as {[key: string]: any})[key].toLowerCase().includes(transformedFilter) + ); } constructor(initialData: T[] = []) {