问题描述
限时送ChatGPT账号..即使我们使用分页,是否有任何解决方案可以从 ui-grid 中获取所有过滤的行?我知道有一个方法
Is there any solution for get all filtered rows from ui-grid even we are using pagination? I know that there is a method
$scope.gridApi.core.getVisibleRows($scope.gridApi.grid);
返回页面上所有可见的行.但是当过滤的数据超过一页时,这种方法不起作用.
which returns all visible rows on page. But this method doesn't help when filtered data is more then one page.
推荐答案
我没有找到任何关于过滤数据的文档,所以我使用的方式是完全手动的.
I didn't find any Documentation about filter data so the way I used is fully manual.
让我们抓住我们拥有的活动过滤器:
Lets grab active filters we have:
function getGridUiFilters(){
var filters_ = _.filter($scope.gridApi.grid.columns, function(_column){
return _column.filter.term !== undefined && _column.filter.term !== null;
});
return filters_;
}
现在我们可以获取所有网格数据并使用您在columnDefs
中定义的过滤器对其进行过滤:
Now we can get all grid data and filter it by using filters you defined in columnDefs
:
function getFilteredDatagridIds(){
var gridFilters = getGridUiFilters();
var gridRows = $scope.gridApi.grid.rows;
var dataRows = _.map(gridRows, function(_row){
return _row.entity; // our object stored in row
});
var filteredDataRows = _.filter(dataRows, function(_row){
var isMatch = true;
angular.forEach(gridFilters, function (_filter) {
// call 'condition' method defined in 'columnDefs'
isMatch = isMatch &&
_filter.filter.condition(_filter.filter.term, _row[_filter.field] );
});
return isMatch;
});
return filteredDataRows;
}
<小时>
在我的例子中 columnDefs
看起来像:
columnDefs: [
{displayName: 'Meeting', field: 'name_obj',
enableSorting: true,
enableColumnMenu: false,
cellTemplate: meetingNameCellTemplate,
headerCellTemplate: meetingNameHeaderCellTemplate,
filter: {
condition: function (searchTerm, cellValue) {
return cellValue.name.toLowerCase().indexOf(searchTerm.toLowerCase()) >= 0;
}
}
}, ....
所以我相信这个例子会对你有所帮助
So I'm sure this example will help you
这篇关于尽管分页,AngularJS ui-grid 仍会过滤出行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论