如何清除AGGRID中的过滤器以获取列名?

问题描述

我需要清除保存的过滤器。为此,我需要列名。

onFilterChanged: function(event){
var newObj = {}
 newObj =  gridOptions.api.getFilterModel();}

在此设置过滤器时,我将获得过滤器详细信息以及列名。但是如果清除过滤器,如何获取列名

如果清除过滤器,

gridOptions.api.getFilterModel();为空。

有什么解决方法吗?

解决方法

现在我们删除过滤条件,网格将过滤器模型设置为null,因此gridOptions.api.getFilterModel();不返回任何内容。

要记住(通过UI或通过编程方式)触摸了哪个过滤器,我们需要监听onFiltermodified事件,因为ag网格首先修改了过滤器(当我们删除条件时),然后应用(更改)了。因此您可以收听此事件,并可以将columnId保存在某个变量中,因为onFilterChange事件在此事件之后。

该解决方法将失败的唯一情况是,您正在以编程方式设置/清除设置过滤器,因为网格会跳过filterModified事件并直接调用Filterchanged事件。但是我希望,如果您以编程方式进行操作,那么您已经有了要添加或删除过滤器的列的列表。

    onFilterModified : function(params){
     // note : set filter does not trigger this event if filtering is done using api
      filtercolId = params.column.colId; // save the colID
    },onFilterChanged : function(params){
    //if filter is removed then gridOptions.api.getFilterModel(); will return empty so 
    //use filtercolId which was stored during filterModified event.
    console.log(params);
    }

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...