nir nir -4 years ago 190
AngularJS Question

UI-GRID - Remove selected rows after row filtering

How can I deselect rows when these rows are filtered from the grid?

Is there any flag in angular-ui-grid that can do this job? Something like:

gridOptions.removeSelectedAfterFilterd = true

Answer Source

like an answer of Tim Harker without need add "$timeout"

var app = angular.module('app', ['ui.grid', 'ui.grid.selection']);
app.controller('MainCtrl', ['$scope', '$timeout',
  function($scope, $timeout) {
    $scope.gridOptions = {
      enableFiltering: true,
      enableSelectAll: true,
      enableRowSelection: true,
      enableRowHeaderSelection: false,
      enableFullRowSelection: true,
      showGridFooter: true,
      onRegisterApi: function(gridApi) {
        $scope.gridApi = gridApi;
        $scope.gridApi.core.on.rowsVisibleChanged($scope, function() {
            angular.forEach($scope.gridApi.selection.getSelectedGridRows(), function(row) {
              if (!row.visible) {

      columnDefs: [{name: 'FirstName'}, {name: 'LastName'}, {name: 'Job'}],
      data: [{"FirstName": "nir", "LastName": "OP", "Job": "Stack Overflow User"},
             {"FirstName": "Tim", "LastName": "Harker", "Job": "Stack Overflow User"},
             {"FirstName": "nir", "LastName": "OP", "Job": "Stack Overflow User"}]
div[ui-grid] {
  height: 190px;
<script src="//"></script>
<script src="//"></script>
<link rel="stylesheet" href="//" />
<div ng-app="app" ng-controller="MainCtrl">
  <div ui-grid="gridOptions" ui-grid-selection class="grid"></div>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download