@@ -154,14 +154,7 @@ export class IgxGridStateBaseDirective {
154154 getFeatureState : ( context : IgxGridStateBaseDirective ) : IGridState => {
155155 const filteringState = context . currGrid . filteringExpressionsTree ;
156156 if ( filteringState ) {
157- const filteringStateCopy = { ...filteringState } ;
158- delete filteringStateCopy . owner ;
159- filteringStateCopy . filteringOperands = filteringState . filteringOperands . map ( item => {
160- const itemCopy = { ...item } ;
161- delete ( itemCopy as IFilteringExpressionsTree ) . owner ;
162- return itemCopy ;
163- } ) ;
164- return { filtering : filteringStateCopy as IFilteringExpressionsTree } ;
157+ return { filtering : context . cloneFilteringTree ( filteringState ) } ;
165158 }
166159 return { filtering : filteringState } ;
167160 } ,
@@ -175,14 +168,7 @@ export class IgxGridStateBaseDirective {
175168 const filteringState = context . currGrid . advancedFilteringExpressionsTree ;
176169 let advancedFiltering : any ;
177170 if ( filteringState ) {
178- const filteringStateCopy = { ...filteringState } ;
179- delete filteringStateCopy . owner ;
180- filteringStateCopy . filteringOperands = filteringState . filteringOperands . map ( item => {
181- const itemCopy = { ...item } ;
182- delete ( itemCopy as IFilteringExpressionsTree ) . owner ;
183- return itemCopy ;
184- } ) ;
185- advancedFiltering = filteringStateCopy ;
171+ advancedFiltering = context . cloneFilteringTree ( filteringState ) ;
186172 } else {
187173 advancedFiltering = { } ;
188174 }
@@ -714,4 +700,20 @@ export class IgxGridStateBaseDirective {
714700 const feature : Feature = this . FEATURES [ key ] ;
715701 return feature ;
716702 }
703+
704+ /**
705+ * Creates a deep clone of an IFilteringExpressionsTree, removing the `owner`
706+ * property at every level so the original live tree is not mutated.
707+ */
708+ private cloneFilteringTree ( tree : IFilteringExpressionsTree ) : IFilteringExpressionsTree {
709+ const copy = { ...tree } ;
710+ delete copy . owner ;
711+ copy . filteringOperands = tree . filteringOperands . map ( item => {
712+ if ( ( item as IFilteringExpressionsTree ) . filteringOperands !== undefined ) {
713+ return this . cloneFilteringTree ( item as IFilteringExpressionsTree ) ;
714+ }
715+ return { ...item } ;
716+ } ) ;
717+ return copy as IFilteringExpressionsTree ;
718+ }
717719}
0 commit comments