How to get the filtered rows in ui-grid?

DeclanMcD picture DeclanMcD · May 9, 2015 · Viewed 16.3k times · Source

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?

Answer

kachhalimbu picture kachhalimbu · May 9, 2015

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)