gpt4 book ai didi

javascript - 如何预先选择 AG-Grid 过滤器下拉复选框值

转载 作者:行者123 更新时间:2023-12-03 01:04:10 25 4
gpt4 key购买 nike

有没有办法为过滤器复选框预先选择一个或多个值?

我当前正在保存最后一个过滤器,因此如果用户过滤,离开页面,然后返回,网格仍会被过滤。我遇到的问题是过滤器下拉复选框不反射(reflect)过滤后的行。

enter image description here

这是我用来设置保存的过滤器的代码:

if ($scope.onFilterChanged) {
this.gridOptions.onFilterModified = function () {
$scope.onFilterChanged({filter: ctrl.gridOptions.api.getFilterModel()});
}
}

if ($scope.currentFilter && $scope.onFilterChanged) {
this.gridOptions.api.setFilterModel($scope.currentFilter);
} else {
this.gridOptions.api.setFilterModel(null);
}

如果我不离开页面并返回,setFilterModel 效果很好。但我不确定为什么它会更新行而不是页面加载时的下拉选项。有没有办法让过滤后的行和复选框在页面加载时匹配?

最佳答案

是的,可以通过filter API

您需要先获取过滤器实例

let filterInstance = this.gridOptions.api.getFilterInstance('columnNameHere');

然后您可以决定过滤器中应包含哪些内容

filterInstance.selectNothing();
filterInstance.selectValue("value one");
filterInstance.selectValue("value two");
...or...
let model = ["value one", "value two"];
filterInstance.setModel(model);

最后一步 - 只需通知网格有关更改

this.gridOptions.api.onFilterChanged();

关于javascript - 如何预先选择 AG-Grid 过滤器下拉复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52486231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com