ag-grid日期列inRange过滤器-如何在测试功能中访问“到”日期?

问题描述

我的日期columnDef包括以下filterOption

{
    displayKey: 'inRange',displayName: 'In range',test: function(filterValue,cellValue) {
        ...
    }
},

我运行时,filterValue只是过滤器的“开始”日期。如何访问test中过滤器的“截止日期”?

我尝试过:

{
    displayKey: 'inRange',test: function(filterValue1,filterValue2,

但这只是将单元格值放入filterValue2中,而cellValue未定义。

如何获取截止日期,以便为inRange编写自定义逻辑?

解决方法

我也有类似的问题,我想使用原型覆盖进行覆盖,但是我发现了另一种解决方法,但它对我有用。您可以在测试函数中调用以下方法。

    gridOptions.api.getFilterModel();

这将为您提供当前列上的filtermodel。您可以使用以下代码

    //getFilterModel() will give you filter JSON object
    var customfilterModel = gridOptions.api.getFilterModel(); 
    var columnName = Object.keys(customfilterModel)[0];
    var customDateFilter = customfilterModel[columnName];

customDateFilter变量将是包含以下属性的对象

    {
    dateFrom: "2020-06-30" //the date which you selected in AGGridDateFilter Popup
    dateTo: "2020-08-27" //the date which you selected in AGGridDateFilter Popup
    filterType: "date"
    type: "inRange"
    }

现在,因为您同时拥有dateFromdateTo属性,所以我想您知道要使用它们做什么。

我认为AG Grid人员应该更新

    return customFilterOption.test(filterText,cellValueFormatted);

上面的语句可以同时返回dateFromdateTo,如下所述,以便开发人员可以针对自定义/复杂日期自定义行为。

    return customFilterOption.test(filterText,cellValueFormatted,filterValueTo);