javascript 如何在 ui-grid 中获取过滤后的行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30139992/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 11:46:51  来源:igfitidea点击:

How to get the filtered rows in ui-grid?

javascriptangularjsangular-ui-grid

提问by DeclanMcD

Using ui-gridI want to get a list of all the filtered data rows using the filter.

使用ui-grid我想使用过滤器获取所有过滤数据行的列表。

In the plunker below I have the original data of 500 items filtered down to 61. Now how do I get a list of those 61 entities?

在下面的 plunker 中,我将 500 个项目的原始数据过滤到 61 个。现在我如何获得这 61 个实体的列表?

plnkr link

链接

If I use the following code I only get the rows rendered on the screen

如果我使用以下代码,我只会得到在屏幕上呈现的行

var _renderedRows = $scope.gridApi.grid.renderContainers.body.renderedRows;

Clicking the button at the bottom of that plunker shows the number of filtered rows which is only 14 as opposed to 61. That works perfectly if there are 14 or less in my filter as I can access the entity object from the above. But I can't see any property in the grid that exposes the filtered rows.

单击该 plunker 底部的按钮会显示过滤的行数,只有 14 行,而不是 61 行。如果我的过滤器中有 14 行或更少,则效果很好,因为我可以从上面访问实体对象。但是我在网格中看不到任何显示过滤行的属性。

So how can I get the list of 61 so I can pass them into another function to perform actions on them?

那么如何获得 61 的列表,以便我可以将它们传递给另一个函数以对它们执行操作?

回答by kachhalimbu

Use the PublicApito get the current visible rows count

使用PublicApi获取当前可见的行数

$scope.filteredRows = $scope.gridApi.core.getVisibleRows($scope.gridApi.grid);

Here is the updated plnkr(Hint: You have to click the "Get filtered rows" button)

这是更新的plnkr(提示:您必须单击“获取过滤的行”按钮)