ag-grid date column inRange filter - 如何访问测试函数中的 "to" 日期?
ag-grid date column inRange filter - how do I access the "to" date in the test function?
我的 columnDef
我的日期列包括这个 filterOption
:
{
displayKey: 'inRange',
displayName: 'In range',
test: function(filterValue, cellValue) {
...
}
},
当我运行时,filterValue
就是过滤器的'from'日期。如何访问 test
中过滤器的 'to' 日期?
我试过了:
{
displayKey: 'inRange',
displayName: 'In range',
test: function(filterValue1, filterValue2, cellValue) {
...
}
},
但这只是将单元格值放入 filterValue2
,而 cellValue
未定义。
如何获取 'to' 日期以便为 inRange
编写自定义逻辑?
我也遇到了类似的问题,并且正在考虑使用原型覆盖来覆盖,但我找到了另一种方法,这是一种解决方法,但它对我有用。你可以在测试函数中调用下面的方法。
gridOptions.api.getFilterModel();
这将为您提供当前列的过滤器模型。您可以使用下面的代码
//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"
}
现在因为您同时拥有 dateFrom
和 dateTo
属性,所以我想您知道要用它们做什么。
我认为 AG Grid 的人应该更新
return customFilterOption.test(filterText, cellValueFormatted);
上面对 return dateFrom
和 dateTo
的声明,就像我在下面提到的那样,以便开发人员可以自定义 custom/complex 日期的行为。
return customFilterOption.test(filterText, cellValueFormatted ,filterValueTo);
我遇到了类似的问题。但使用 'predicate' 而不是 'test' 它解决了。
谓词函数采用值数组,具体取决于 'number Of Inputs' 定义。
https://ag-grid.com/javascript-data-grid/filter-provided-simple/#reference-IFilterOptionDef-predicate
用法将是这样的:
{
displayKey: 'inRange', displayName: 'In Range', numberOfInputs: 2, predicate: ([fv1, fv2], cellValue) => {
var cellDate = new Date(cellValue);
return (fv1 < cellDate && fv2 > cellDate);
}
}
我的 columnDef
我的日期列包括这个 filterOption
:
{
displayKey: 'inRange',
displayName: 'In range',
test: function(filterValue, cellValue) {
...
}
},
当我运行时,filterValue
就是过滤器的'from'日期。如何访问 test
中过滤器的 'to' 日期?
我试过了:
{
displayKey: 'inRange',
displayName: 'In range',
test: function(filterValue1, filterValue2, cellValue) {
...
}
},
但这只是将单元格值放入 filterValue2
,而 cellValue
未定义。
如何获取 'to' 日期以便为 inRange
编写自定义逻辑?
我也遇到了类似的问题,并且正在考虑使用原型覆盖来覆盖,但我找到了另一种方法,这是一种解决方法,但它对我有用。你可以在测试函数中调用下面的方法。
gridOptions.api.getFilterModel();
这将为您提供当前列的过滤器模型。您可以使用下面的代码
//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"
}
现在因为您同时拥有 dateFrom
和 dateTo
属性,所以我想您知道要用它们做什么。
我认为 AG Grid 的人应该更新
return customFilterOption.test(filterText, cellValueFormatted);
上面对 return dateFrom
和 dateTo
的声明,就像我在下面提到的那样,以便开发人员可以自定义 custom/complex 日期的行为。
return customFilterOption.test(filterText, cellValueFormatted ,filterValueTo);
我遇到了类似的问题。但使用 'predicate' 而不是 'test' 它解决了。 谓词函数采用值数组,具体取决于 'number Of Inputs' 定义。 https://ag-grid.com/javascript-data-grid/filter-provided-simple/#reference-IFilterOptionDef-predicate 用法将是这样的:
{
displayKey: 'inRange', displayName: 'In Range', numberOfInputs: 2, predicate: ([fv1, fv2], cellValue) => {
var cellDate = new Date(cellValue);
return (fv1 < cellDate && fv2 > cellDate);
}
}