|
1 | 1 | import { FilteringLogic, IFilteringExpression } from './filtering-expression.interface'; |
2 | 2 | import { FilteringExpressionsTree, IFilteringExpressionsTree } from './filtering-expressions-tree'; |
3 | 3 | import { resolveNestedPath, parseDate, formatDate, formatCurrency } from '../core/utils'; |
4 | | -import { ColumnType, GridType } from '../grids/common/grid.interface'; |
| 4 | +import { 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 | 8 | import { IFilteringState } from './filtering-state.interface'; |
9 | 9 | import { isTree } from './expressions-tree-util'; |
| 10 | +import { IgxHierarchicalGridComponent } from '../grids/hierarchical-grid/hierarchical-grid.component'; |
10 | 11 |
|
11 | 12 | const DateType = 'date'; |
12 | 13 | const DateTimeType = 'dateTime'; |
@@ -94,23 +95,42 @@ export abstract class BaseFilteringStrategy implements IFilteringStrategy { |
94 | 95 | return true; |
95 | 96 | } else { |
96 | 97 | const expression = expressions; |
97 | | - let isDate = false; |
98 | | - let isTime = false; |
| 98 | + let dataType = null; |
99 | 99 | if (!entity) { |
100 | 100 | const column = grid && grid.getColumnByName(expression.fieldName); |
101 | | - isDate = column ? column.dataType === DateType || column.dataType === DateTimeType : false; |
102 | | - isTime = column ? column.dataType === TimeType : false; |
103 | | - } else { |
104 | | - // TODO: check for date and time |
| 101 | + dataType = column.dataType; |
| 102 | + } else if (grid.type === 'hierarchical') { |
| 103 | + const schema = (grid as IgxHierarchicalGridComponent).schema; |
| 104 | + const entityMatch = this.findEntityByName(schema, 'entity'); |
| 105 | + dataType = entityMatch?.fields.find(f => f.field === expression.fieldName)?.dataType; |
105 | 106 | } |
106 | 107 |
|
| 108 | + const isDate = dataType ? dataType === DateType || dataType === DateTimeType : false; |
| 109 | + const isTime = dataType ? dataType === TimeType : false; |
| 110 | + |
107 | 111 | return this.findMatchByExpression(rec, expression, isDate, isTime, grid); |
108 | 112 | } |
109 | 113 | } |
110 | 114 |
|
111 | 115 | return true; |
112 | 116 | } |
113 | 117 |
|
| 118 | + private findEntityByName(schema: EntityType[], name: string): EntityType | null { |
| 119 | + for (const entity of schema) { |
| 120 | + if (entity.name === name) { |
| 121 | + return entity; |
| 122 | + } |
| 123 | + |
| 124 | + if (entity.childEntities && entity.childEntities.length > 0) { |
| 125 | + const found = this.findEntityByName(entity.childEntities, name); |
| 126 | + if (found) { |
| 127 | + return found; |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + return null; |
| 132 | + } |
| 133 | + |
114 | 134 | public getFilterItems(column: ColumnType, tree: IFilteringExpressionsTree): Promise<IgxFilterItem[]> { |
115 | 135 |
|
116 | 136 | let data = column.grid.gridAPI.filterDataByExpressions(tree); |
|
0 commit comments