如何从分页的ui-grid获取过滤数据

Mah*_*hdi 6 javascript angularjs angular-ui-grid

我想在启用分页功能时从ui网格中获取过滤数据.一般情况下我用过

 $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);
            });
Run Code Online (Sandbox Code Playgroud)

但是当启用分页时,代码不能很好地工作,它只返回第一页的行.但我需要所有过滤后的数据.

最简单的解决方案是基于过滤器术语过滤数据源,但它会显着降低性能.

任何建议?

Pat*_*ova 12

注意:我没有尝试分页,只是分组,但希望它能给你一个提示.


尝试将rowsVisibleChanged事件与事件一起使用filterChanged.您必须使用两者,因为如果您filterChanged单独使用该事件,它将无法工作,因为它是在实际过滤行之前启动的.我使用标志变量(filterChanged)来知道过滤器是否被修改.

然后,使用类似lodash筛选$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
});
Run Code Online (Sandbox Code Playgroud)