ag grid : js : How to find which filter is applied

不问归期 提交于 2020-05-15 19:10:49

问题


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

  1. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!