尽管分页,AngularJS ui

编程入门 行业动态 更新时间:2024-10-28 19:33:49
本文介绍了尽管分页,AngularJS ui-grid 仍会过滤出行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-21 05:34:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/998284.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   AngularJS   ui

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!