问题
I have data displayed in ag grid. It has 4 columns name,age,sport and has the following data:-
data
now when I filter the data based on "sport" , lets say uncheck "blanks" I get the following data:- filtered data
1)My questions is how to get the which filter is applied on columns , like in this case "blanks" is applied on "sport".
2)If I refresh the data using api.setRowdata(), filter applied to the columns are lost
回答1:
1.how to get the which filter is applied on columns
You can get it using gridApi.filterManager.allFilters
Check this live example ag-grid: Built-In Filters - log the filters applied.
Apply age
and year
filters and then click Log Filter
button.
age: {column: Column, filterPromise: Promise, scope: null, compiledElement: null, guiPromise: {…}}
year: {column: Column, filterPromise: Promise, scope: null, compiledElement: null, guiPromise: {…}}
__proto__: Object
回答2:
Starting from ag-grid@19.0.0
to get or set all applied filters you can take advantage of using:
const savedModel = gridApi.getFilterModel();
gridApi.setFilterModel(savedModel);
回答3:
For the
- if I refresh the data using
api.setRowdata()
, filter applied to the columns are lost
we can use the following settings for columns in columnDefs
object :-
filterParams: {
newRowsAction: 'keep'
}
来源:https://stackoverflow.com/questions/51039682/ag-grid-js-how-to-find-which-filter-is-applied