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' ;
5
5
import { GridColumnDataType } from './data-util' ;
6
6
import { SortingDirection } from './sorting-strategy' ;
7
7
import { formatNumber , formatPercent , getLocaleCurrencyCode } from '@angular/common' ;
8
- import { IFilteringState } from './filtering-state.interface' ;
8
+ import type { IFilteringState } from './filtering-state.interface' ;
9
9
import { 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' ;
11
11
12
12
const DateType = 'date' ;
13
13
const DateTimeType = 'dateTime' ;
@@ -26,7 +26,7 @@ export interface IFilteringStrategy {
26
26
filter ( data : any [ ] , expressionsTree : IFilteringExpressionsTree , advancedExpressionsTree ?: IFilteringExpressionsTree ,
27
27
grid ?: GridType ) : any [ ] ;
28
28
/* csSuppress */
29
- getFilterItems ( column : ColumnType , tree : IFilteringExpressionsTree ) : Promise < IgxFilterItem [ ] > ;
29
+ getFilterItems ( column : ColumnType , tree : IFilteringExpressionsTree ) : Promise < IgxFilterItem [ ] > ;
30
30
}
31
31
32
32
/* csSuppress */
@@ -37,16 +37,14 @@ export interface IgxFilterItem {
37
37
}
38
38
39
39
/* csSuppress */
40
- export abstract class BaseFilteringStrategy implements IFilteringStrategy {
40
+ export abstract class BaseFilteringStrategy implements IFilteringStrategy {
41
41
// protected
42
42
public findMatchByExpression ( rec : any , expr : IFilteringExpression , isDate ?: boolean , isTime ?: boolean , grid ?: GridType ) : boolean {
43
43
if ( expr . searchTree ) {
44
44
const records = rec [ expr . searchTree . entity ] ;
45
45
const shouldMatchRecords = expr . conditionName === 'inQuery' ;
46
46
if ( ! records ) { // child grid is not yet created
47
47
return true ;
48
- } else if ( records . length === 0 ) { // child grid is empty
49
- return false ;
50
48
}
51
49
52
50
for ( let index = 0 ; index < records . length ; index ++ ) {
@@ -74,7 +72,7 @@ export abstract class BaseFilteringStrategy implements IFilteringStrategy {
74
72
const operator = expressionsTree . operator as FilteringLogic ;
75
73
let matchOperand ;
76
74
77
- if ( expressionsTree . filteringOperands && expressionsTree . filteringOperands . length ) {
75
+ if ( expressionsTree . filteringOperands ? .length ) {
78
76
for ( const operand of expressionsTree . filteringOperands ) {
79
77
matchOperand = this . matchRecord ( rec , operand , grid , entity ) ;
80
78
@@ -132,19 +130,18 @@ export abstract class BaseFilteringStrategy implements IFilteringStrategy {
132
130
}
133
131
134
132
public getFilterItems ( column : ColumnType , tree : IFilteringExpressionsTree ) : Promise < IgxFilterItem [ ] > {
133
+ const applyFormatter = column . formatter && this . shouldFormatFilterValues ( column ) ;
135
134
136
135
let data = column . grid . gridAPI . filterDataByExpressions ( tree ) ;
137
136
data = column . grid . gridAPI . sortDataByExpressions ( data ,
138
137
[ { fieldName : column . field , dir : SortingDirection . Asc , ignoreCase : column . sortingIgnoreCase } ] ) ;
139
138
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 ) ;
144
139
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 ) ;
148
145
149
146
return {
150
147
value,
@@ -239,36 +236,25 @@ export class NoopFilteringStrategy extends BaseFilteringStrategy {
239
236
export class FilteringStrategy extends BaseFilteringStrategy {
240
237
private static _instance : FilteringStrategy = null ;
241
238
242
- constructor ( ) {
243
- super ( ) ;
244
- }
245
239
246
240
public static instance ( ) {
247
241
return this . _instance || ( this . _instance = new this ( ) ) ;
248
242
}
249
243
250
244
public filter < T > ( data : T [ ] , expressionsTree : IFilteringExpressionsTree , advancedExpressionsTree : IFilteringExpressionsTree ,
251
245
grid : GridType ) : T [ ] {
252
- let i ;
253
- let rec ;
254
- const len = data . length ;
255
- const res : T [ ] = [ ] ;
256
246
257
- if ( ( FilteringExpressionsTree . empty ( expressionsTree ) && FilteringExpressionsTree . empty ( advancedExpressionsTree ) ) || ! len ) {
247
+
248
+ if ( ( FilteringExpressionsTree . empty ( expressionsTree ) && FilteringExpressionsTree . empty ( advancedExpressionsTree ) ) ) {
258
249
return data ;
259
250
}
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 ) ) ;
267
253
}
268
254
269
255
protected getFieldValue ( rec : any , fieldName : string , isDate = false , isTime = false , grid ?: GridType ) : any {
270
256
const column = grid ?. getColumnByName ( fieldName ) ;
271
- let value = resolveNestedPath ( rec , fieldName ) ;
257
+ let value = resolveNestedPath ( rec , columnFieldPath ( fieldName ) ) ;
272
258
273
259
value = column ?. formatter && this . shouldFormatFilterValues ( column ) ?
274
260
column . formatter ( value , rec ) :
0 commit comments