我想在启用分页功能时从用户界面网格中获取过滤后的数据。一般情况下我使用
$scope.gridApi.core.on.filterChanged($scope, function () {
if ($scope.gridApi.grid.columns[1].filter.term != "" && $scope.gridApi.grid.columns[1].filter.term != undefined) {
var dd =$scope.gridApi.core.getVisibleRows($scope.gridApi.grid);
console.log(dd);
});
但是当启用分页时,代码不能正常工作,它仅返回第一页的行。但我需要所有过滤后的数据。
最简单的解决方案是根据过滤条件过滤数据源,但它会显着降低性能。
有什么建议吗?
Note:我没有尝试分页,只是分组,但希望它能给你一个提示。
尝试使用rowsVisibleChanged
活动与filterChanged
事件。你必须同时使用两者,因为如果你使用filterChanged
单独的事件将不起作用,因为它是在实际过滤行之前启动的。我使用一个标志变量(filterChanged
)以了解过滤器是否被修改。
然后,使用类似的东西lodash https://lodash.com/docs#filter来过滤$scope.gridApi.grid.rows
那些有visible
属性设置为true
:
// UI-Grid v.3.0.7
var filterChanged = false;
$scope.gridApi.core.on.filterChanged($scope, function() {
filterChanged = true;
});
$scope.gridApi.core.on.rowsVisibleChanged($scope, function() {
if(!filterChanged){
return;
}
filterChanged = false;
// The following line extracts the filtered rows
var filtered = _.filter($scope.gridApi.grid.rows, function(o) { return o.visible; });
var entities = _.map(filtered, 'entity'); // Entities extracted from the GridRow array
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)