如何从分页UI格过滤数据 [英] How to Get Filtered data from paged ui-grid
问题描述
我想启用了分页功能时,从UI电网得到过滤后的数据。在一般情况下,我用
I'd like to get filtered data from a ui-grid when the paging feature is enabled. In general case I used
$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);
});
但code不能很好地工作在启用分页,它返回第一页的唯一行。但我需要所有的过滤后的数据。
but the code doesn't work well when the paging is enabled, it return only rows of the first page. but I need all the filtered data.
的最简单的解决方案是基于所述滤波器术语滤波数据源,但它显着地降低了性能。
the easiest solution is filter data source based on the filter term but it decreases the performance dramatically.
什么建议吗?
推荐答案
注意:我没有分页尝试,只是分组,而是希望它给你一个提示。
一起试试使用 rowsVisibleChanged
事件与 filterChanged
事件。你必须同时使用,因为如果你单独使用 filterChanged
事件就不会工作,因为实际上是过滤行之前,它的推出。我用一个标志变量( filterChanged
)知道,如果过滤器被修改。
Note: I didn't try it with pagination, just grouping, but hope it gives you a hint.
Try using the rowsVisibleChanged
event together with the filterChanged
event. You have to use both because if you use the filterChanged
event alone it won't work since it's launched before the rows are actually filtered. I use a flag variable (filterChanged
) to know if a filter was modified.
然后,使用类似 lodash 过滤 $ scope.gridApi。 grid.rows
已经在可见
属性设置为真正
:
Then, use something like lodash to filter the $scope.gridApi.grid.rows
that have the visible
property set to 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
});
这篇关于如何从分页UI格过滤数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!