How to get the filtered rows in ui-grid?
Asked Answered
B

1

10

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

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?

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.

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

Bohlin answered 9/5, 2015 at 12:35 Comment(1)
This is an answer to a similar question. It acknowledges not only visible rows, but rows that are actually filtered: https://mcmap.net/q/1161381/-how-to-get-filtered-data-from-paged-ui-gridDerek
P
27

Use the PublicApi to get the current visible rows count

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

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

Pfeifer answered 9/5, 2015 at 12:47 Comment(2)
I believe this only gets those set to visible, which if you have paging enabled will max out at the page size. Haven't come across something that specifically gets all filtered rows (across all pages) yet myself, but I'm looking...Riba
if you use grouping and treeNodes, the property treeNode.row.visible === true, worked for me, to get filtered grouped rows. Without pagination.Judo

© 2022 - 2024 — McMap. All rights reserved.