1- import { FilteringLogic , IFilteringExpression } from './filtering-expression.interface' ;
2- import { FilteringExpressionsTree , IFilteringExpressionsTree } from './filtering-expressions-tree' ;
3- import { resolveNestedPath , parseDate , formatDate , formatCurrency } from '../core/utils' ;
4- import { ColumnType , EntityType , GridType } from '../grids/common/grid.interface' ;
1+ import { FilteringLogic , type IFilteringExpression } from './filtering-expression.interface' ;
2+ import { FilteringExpressionsTree , type IFilteringExpressionsTree } from './filtering-expressions-tree' ;
3+ import { resolveNestedPath , parseDate , formatDate , formatCurrency , columnFieldPath } from '../core/utils' ;
4+ import type { ColumnType , EntityType , GridType } from '../grids/common/grid.interface' ;
55import { GridColumnDataType } from './data-util' ;
66import { SortingDirection } from './sorting-strategy' ;
77import { formatNumber , formatPercent , getLocaleCurrencyCode } from '@angular/common' ;
8- import { IFilteringState } from './filtering-state.interface' ;
8+ import type { IFilteringState } from './filtering-state.interface' ;
99import { isTree } from './expressions-tree-util' ;
10- import { IgxHierarchicalGridComponent } from '../grids/hierarchical-grid/hierarchical-grid.component' ;
10+ import type { IgxHierarchicalGridComponent } from '../grids/hierarchical-grid/hierarchical-grid.component' ;
1111
1212const DateType = 'date' ;
1313const DateTimeType = 'dateTime' ;
@@ -26,7 +26,7 @@ export interface IFilteringStrategy {
2626 filter ( data : any [ ] , expressionsTree : IFilteringExpressionsTree , advancedExpressionsTree ?: IFilteringExpressionsTree ,
2727 grid ?: GridType ) : any [ ] ;
2828 /* csSuppress */
29- getFilterItems ( column : ColumnType , tree : IFilteringExpressionsTree ) : Promise < IgxFilterItem [ ] > ;
29+ getFilterItems ( column : ColumnType , tree : IFilteringExpressionsTree ) : Promise < IgxFilterItem [ ] > ;
3030}
3131
3232/* csSuppress */
@@ -37,16 +37,14 @@ export interface IgxFilterItem {
3737}
3838
3939/* csSuppress */
40- export abstract class BaseFilteringStrategy implements IFilteringStrategy {
40+ export abstract class BaseFilteringStrategy implements IFilteringStrategy {
4141 // protected
4242 public findMatchByExpression ( rec : any , expr : IFilteringExpression , isDate ?: boolean , isTime ?: boolean , grid ?: GridType ) : boolean {
4343 if ( expr . searchTree ) {
4444 const records = rec [ expr . searchTree . entity ] ;
4545 const shouldMatchRecords = expr . conditionName === 'inQuery' ;
4646 if ( ! records ) { // child grid is not yet created
4747 return true ;
48- } else if ( records . length === 0 ) { // child grid is empty
49- return false ;
5048 }
5149
5250 for ( let index = 0 ; index < records . length ; index ++ ) {
@@ -74,7 +72,7 @@ export abstract class BaseFilteringStrategy implements IFilteringStrategy {
7472 const operator = expressionsTree . operator as FilteringLogic ;
7573 let matchOperand ;
7674
77- if ( expressionsTree . filteringOperands && expressionsTree . filteringOperands . length ) {
75+ if ( expressionsTree . filteringOperands ? .length ) {
7876 for ( const operand of expressionsTree . filteringOperands ) {
7977 matchOperand = this . matchRecord ( rec , operand , grid , entity ) ;
8078
@@ -132,19 +130,18 @@ export abstract class BaseFilteringStrategy implements IFilteringStrategy {
132130 }
133131
134132 public getFilterItems ( column : ColumnType , tree : IFilteringExpressionsTree ) : Promise < IgxFilterItem [ ] > {
133+ const applyFormatter = column . formatter && this . shouldFormatFilterValues ( column ) ;
135134
136135 let data = column . grid . gridAPI . filterDataByExpressions ( tree ) ;
137136 data = column . grid . gridAPI . sortDataByExpressions ( data ,
138137 [ { fieldName : column . field , dir : SortingDirection . Asc , ignoreCase : column . sortingIgnoreCase } ] ) ;
139138
140- const columnField = column . field ;
141- let filterItems : IgxFilterItem [ ] = data . map ( record => {
142- let value = resolveNestedPath ( record , columnField ) ;
143- const applyFormatter = column . formatter && this . shouldFormatFilterValues ( column ) ;
144139
145- value = applyFormatter ?
146- column . formatter ( value , record ) :
147- value ;
140+ const pathParts = columnFieldPath ( column . field )
141+ let filterItems : IgxFilterItem [ ] = data . map ( record => {
142+ const value = applyFormatter ?
143+ column . formatter ( resolveNestedPath ( record , pathParts ) , record ) :
144+ resolveNestedPath ( record , pathParts ) ;
148145
149146 return {
150147 value,
@@ -239,36 +236,25 @@ export class NoopFilteringStrategy extends BaseFilteringStrategy {
239236export class FilteringStrategy extends BaseFilteringStrategy {
240237 private static _instance : FilteringStrategy = null ;
241238
242- constructor ( ) {
243- super ( ) ;
244- }
245239
246240 public static instance ( ) {
247241 return this . _instance || ( this . _instance = new this ( ) ) ;
248242 }
249243
250244 public filter < T > ( data : T [ ] , expressionsTree : IFilteringExpressionsTree , advancedExpressionsTree : IFilteringExpressionsTree ,
251245 grid : GridType ) : T [ ] {
252- let i ;
253- let rec ;
254- const len = data . length ;
255- const res : T [ ] = [ ] ;
256246
257- if ( ( FilteringExpressionsTree . empty ( expressionsTree ) && FilteringExpressionsTree . empty ( advancedExpressionsTree ) ) || ! len ) {
247+
248+ if ( ( FilteringExpressionsTree . empty ( expressionsTree ) && FilteringExpressionsTree . empty ( advancedExpressionsTree ) ) ) {
258249 return data ;
259250 }
260- for ( i = 0 ; i < len ; i ++ ) {
261- rec = data [ i ] ;
262- if ( this . matchRecord ( rec , expressionsTree , grid ) && this . matchRecord ( rec , advancedExpressionsTree , grid ) ) {
263- res . push ( rec ) ;
264- }
265- }
266- return res ;
251+
252+ return data . filter ( record => this . matchRecord ( record , expressionsTree , grid ) && this . matchRecord ( record , advancedExpressionsTree , grid ) ) ;
267253 }
268254
269255 protected getFieldValue ( rec : any , fieldName : string , isDate = false , isTime = false , grid ?: GridType ) : any {
270256 const column = grid ?. getColumnByName ( fieldName ) ;
271- let value = resolveNestedPath ( rec , fieldName ) ;
257+ let value = resolveNestedPath ( rec , columnFieldPath ( fieldName ) ) ;
272258
273259 value = column ?. formatter && this . shouldFormatFilterValues ( column ) ?
274260 column . formatter ( value , rec ) :
0 commit comments