Posted 9 May 2023, 4:04 pm EST
ok sure. Here is the code sample, when some Ajax operation completes, we need to set the data source of the flex grid as mentioned below:
this.data = earningList.filter(x => x.earningID > 0);
above code will reset any filter state of the grid so to avoid this situation, we are storing the original filtered state in local storage on filter change event like this:
onFilterChanged(filter, event, clearClicked=false) {
if (!clearClicked) {
if (filter.cancel) {
return; //filter not applied
}
if(JSON.parse(filter.filterDefinition).filters.length > 0) {
this.filterDefination = filter.filterDefinition;
var state = {
columns: this.flex.columnLayout,
filterDefinition: this.filterDefination,
sortDescriptions: this.flex.collectionView.sortDescriptions.map(function (sortDesc) {
return { property: sortDesc.property, ascending: sortDesc.ascending };
})
};
localStorage['filterState'] = JSON.stringify(state);
}
setTimeout(() => {
this.restoreFilter();
}, 50);
}
}
To restore the filtered state after the ajax operation from local storage, we are using below code:
restoreFilter() {
var filterState = localStorage['filterState'];
if (!this.clearClicked && filterState !== '') {
this.gridFilter = new wjGridFilter.FlexGridFilter(this.flex);
var state = JSON.parse(filterState);
// restore filter definitions
this.gridFilter.filterDefinition = state.filterDefinition;
this.flex.columnLayout = state.columns;
this.flex.getColumn('workerID').dataMap = this.workerMap;
this.flex.getColumn('projectID').dataMap = this.costCodeIDMap;
this.flex.getColumn('addCrewID').dataMap = this.crewMap;
this.flex.getColumn('craftCode').dataMap = this.craftsMap;
this.flex.getColumn('separateCheck').dataMap = this.separateCheckMap;
this.flex.getColumn('eC3').dataMap = this.pdcCodeMap;
this.flex.getColumn('pdcc').dataMap = this.pdccMap;
this.flex.getColumn('opcc').dataMap = this.opccMap;
this.flex.getColumn('eC1').dataMap = this.earningCodeMap;
this.flex.getColumn('eC2').dataMap = this.earningCodeMap;
// restore sort state
var view = this.flex.collectionView;
view.deferUpdate(function () {
view.sortDescriptions.clear();
for (var i = 0; i < state.sortDescriptions.length; i++) {
var sortDesc = state.sortDescriptions[i];
view.sortDescriptions.push(
new wjCore.SortDescription(sortDesc.property, sortDesc.ascending)
);
}
});
}
}
so these all things working properly now but the issue is with column filter’s clear operation, when i clear any column filter, its not clearing column’s filter