Skip to content

Commit eabff1e

Browse files
committed
Fix(saveState): fix #3397 saveState shouldn't save some bits of filters
1 parent 679b615 commit eabff1e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

misc/tutorial/208_save_state.ngdoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ to something different, and use the restore button to set the grid back the way
4949
saveFocus: false,
5050
saveScroll: true,
5151
saveGroupingExpandedStates: true,
52+
enableFiltering: true,
53+
columnDefs: [
54+
{ name: 'name' },
55+
{ name: 'gender' },
56+
{ name: 'company' }
57+
],
5258
onRegisterApi: function(gridApi){
5359
$scope.gridApi = gridApi;
5460
}
5561
};
56-
$scope.gridOptions.enableFiltering = true;
5762
$scope.state = {};
58-
63+
5964
$scope.saveState = function() {
6065
$scope.state = $scope.gridApi.saveState.save();
6166
};

src/features/saveState/js/saveState.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,16 @@
357357
}
358358

359359
if ( grid.options.saveFilter ){
360-
savedColumn.filters = angular.copy ( column.filters );
360+
savedColumn.filters = [];
361+
column.filters.forEach( function( filter ){
362+
var copiedFilter = {};
363+
angular.forEach( filter, function( value, key) {
364+
if ( key !== 'condition' && key !== '$$hashKey' && key !== 'placeholder'){
365+
copiedFilter[key] = value;
366+
}
367+
});
368+
savedColumn.filters.push(copiedFilter);
369+
});
361370
}
362371

363372
if ( !!grid.api.pinning && grid.options.savePinning ){
@@ -545,7 +554,12 @@
545554

546555
if ( grid.options.saveFilter &&
547556
!angular.equals(currentCol.filters, columnState.filters ) ){
548-
currentCol.filters = angular.copy( columnState.filters );
557+
columnState.filters.forEach( function( filter, index ){
558+
angular.extend( currentCol.filters[index], filter );
559+
if ( typeof(filter.term) === 'undefined' || filter.term === null ){
560+
delete currentCol.filters[index].term;
561+
}
562+
});
549563
grid.api.core.raise.filterChanged();
550564
}
551565

0 commit comments

Comments
 (0)