11import { Directive , Optional , Input , Host , ViewContainerRef , Inject , createComponent , EnvironmentInjector , Injector } from '@angular/core' ;
2- import { FilteringExpressionsTree , IFilteringExpressionsTree } from '../data-operations/filtering-expressions-tree' ;
3- import { IFilteringExpression } from '../data-operations/filtering-expression.interface' ;
2+ import { IExpressionTree , IFilteringExpressionsTree } from '../data-operations/filtering-expressions-tree' ;
43import { IgxColumnComponent } from './columns/column.component' ;
54import { IgxColumnGroupComponent } from './columns/column-group.component' ;
65import { IGroupingExpression } from '../data-operations/grouping-expression.interface' ;
76import { IPagingState } from '../data-operations/paging-state.interface' ;
87import { GridColumnDataType } from '../data-operations/data-util' ;
9- import {
10- IgxBooleanFilteringOperand , IgxNumberFilteringOperand , IgxDateFilteringOperand ,
11- IgxStringFilteringOperand , IFilteringOperation , IgxDateTimeFilteringOperand
12- } from '../data-operations/filtering-condition' ;
138import { IGroupByExpandState } from '../data-operations/groupby-expand-state.interface' ;
149import { IGroupingState } from '../data-operations/groupby-state.interface' ;
1510import { IgxGridComponent } from './grid/grid.component' ;
@@ -22,6 +17,7 @@ import { IPivotConfiguration, IPivotDimension } from './pivot-grid/pivot-grid.in
2217import { PivotUtil } from './pivot-grid/pivot-util' ;
2318import { IgxPivotDateDimension } from './pivot-grid/pivot-grid-dimensions' ;
2419import { cloneArray , cloneValue } from '../core/utils' ;
20+ import { recreateTreeFromFields } from '../data-operations/expressions-tree-util' ;
2521
2622export interface IGridState {
2723 columns ?: IColumnState [ ] ;
@@ -158,9 +154,9 @@ export class IgxGridStateBaseDirective {
158154 }
159155 return { filtering : filteringState } ;
160156 } ,
161- restoreFeatureState : ( context : IgxGridStateBaseDirective , state : FilteringExpressionsTree ) : void => {
157+ restoreFeatureState : ( context : IgxGridStateBaseDirective , state : IFilteringExpressionsTree ) : void => {
162158 const filterTree = context . createExpressionsTreeFromObject ( state ) ;
163- context . currGrid . filteringExpressionsTree = filterTree as FilteringExpressionsTree ;
159+ context . currGrid . filteringExpressionsTree = filterTree as IFilteringExpressionsTree ;
164160 }
165161 } ,
166162 advancedFiltering : {
@@ -178,9 +174,9 @@ export class IgxGridStateBaseDirective {
178174 }
179175 return { advancedFiltering } ;
180176 } ,
181- restoreFeatureState : ( context : IgxGridStateBaseDirective , state : FilteringExpressionsTree ) : void => {
177+ restoreFeatureState : ( context : IgxGridStateBaseDirective , state : IFilteringExpressionsTree ) : void => {
182178 const filterTree = context . createExpressionsTreeFromObject ( state ) ;
183- context . currGrid . advancedFilteringExpressionsTree = filterTree as FilteringExpressionsTree ;
179+ context . currGrid . advancedFilteringExpressionsTree = filterTree as IFilteringExpressionsTree ;
184180 }
185181 } ,
186182 columns : {
@@ -590,7 +586,7 @@ export class IgxGridStateBaseDirective {
590586 }
591587 // restore complex filters
592588 if ( dim . filter ) {
593- dim . filter = this . createExpressionsTreeFromObject ( dim . filter as FilteringExpressionsTree ) ;
589+ dim . filter = this . createExpressionsTreeFromObject ( dim . filter ) as IFilteringExpressionsTree ;
594590 }
595591 }
596592 }
@@ -641,78 +637,14 @@ export class IgxGridStateBaseDirective {
641637 }
642638
643639 /**
644- * This method builds a FilteringExpressionsTree from a provided object.
640+ * This method builds a rehydrated IExpressionTree from a provided object.
645641 */
646- private createExpressionsTreeFromObject ( exprTreeObject : FilteringExpressionsTree ) : FilteringExpressionsTree {
642+ private createExpressionsTreeFromObject ( exprTreeObject : IExpressionTree ) : IExpressionTree {
647643 if ( ! exprTreeObject || ! exprTreeObject . filteringOperands ) {
648644 return null ;
649645 }
650646
651- const expressionsTree = new FilteringExpressionsTree ( exprTreeObject . operator , exprTreeObject . fieldName ) ;
652-
653- for ( const item of exprTreeObject . filteringOperands ) {
654- // Check if item is an expressions tree or a single expression.
655- if ( ( item as FilteringExpressionsTree ) . filteringOperands ) {
656- const subTree = this . createExpressionsTreeFromObject ( ( item as FilteringExpressionsTree ) ) ;
657- expressionsTree . filteringOperands . push ( subTree ) ;
658- } else {
659- const expr = item as IFilteringExpression ;
660- let dataType : string ;
661- if ( this . currGrid instanceof IgxPivotGridComponent ) {
662- dataType = this . currGrid . allDimensions . find ( x => x . memberName === expr . fieldName ) . dataType ;
663- } else if ( this . currGrid . columns . length > 0 ) {
664- dataType = this . currGrid . columns . find ( c => c . field === expr . fieldName ) . dataType ;
665- } else if ( this . state . columns ) {
666- dataType = this . state . columns . find ( c => c . field === expr . fieldName ) . dataType ;
667- } else {
668- return null ;
669- }
670- // when ESF, values are stored in Set.
671- // First those values are converted to an array before returning string in the stringifyCallback
672- // now we need to convert those back to Set
673- if ( Array . isArray ( expr . searchVal ) ) {
674- expr . searchVal = new Set ( expr . searchVal ) ;
675- } else {
676- expr . searchVal = expr . searchVal && ( dataType === 'date' || dataType === 'dateTime' ) ? new Date ( Date . parse ( expr . searchVal . toString ( ) ) ) : expr . searchVal ;
677- }
678-
679- const condition = this . generateFilteringCondition ( dataType , expr . condition . name ) ||
680- this . currGrid . columns . find ( c => c . field === expr . fieldName ) . filters . condition ( expr . condition . name ) ;
681-
682- if ( condition ) {
683- expr . condition = condition ;
684- expressionsTree . filteringOperands . push ( expr ) ;
685- }
686- }
687- }
688-
689- return expressionsTree ;
690- }
691-
692- /**
693- * Returns the filtering logic function for a given dataType and condition (contains, greaterThan, etc.)
694- */
695- private generateFilteringCondition ( dataType : string , name : string ) : IFilteringOperation {
696- let filters ;
697- switch ( dataType ) {
698- case GridColumnDataType . Boolean :
699- filters = IgxBooleanFilteringOperand . instance ( ) ;
700- break ;
701- case GridColumnDataType . Number :
702- filters = IgxNumberFilteringOperand . instance ( ) ;
703- break ;
704- case GridColumnDataType . Date :
705- filters = IgxDateFilteringOperand . instance ( ) ;
706- break ;
707- case GridColumnDataType . DateTime :
708- filters = IgxDateTimeFilteringOperand . instance ( ) ;
709- break ;
710- case GridColumnDataType . String :
711- default :
712- filters = IgxStringFilteringOperand . instance ( ) ;
713- break ;
714- }
715- return filters . condition ( name ) ;
647+ return recreateTreeFromFields ( exprTreeObject , this . currGrid . columns ) as IExpressionTree ;
716648 }
717649
718650 protected stringifyCallback ( key : string , val : any ) {
0 commit comments