Search code examples
angularjsangular-ui-gridui-grid

Get filtered data from ui-grid in controller


Is there any way we can get all the filtered data from ui-grid to controller to perform some processing. Intially i have 100 records, on applying some filter it gives 10 records, I need those 10 records in controller.

enter image description here

As shown in image I need only the filtered record. I need to use filtered value somewhere else.

Thanks.


Solution

  • A little more stack overflow provided me answer

    onRegisterApi: function(gridApi){
      $scope.gridApi = gridApi;
      gridApi.core.on.filterChanged($scope, onFilterChanged);
    },
    
    $scope.filteredRows=[];
    function onFilterChanged()
      {
        console.log('no arguments passed:', arguments)
        $scope.filtered = $scope.gridApi.core.getVisibleRows();
        console.log('grid filtered data', $scope.filtered)
      }
    

    Thanks