angular-ui / ui-grid

UI Grid: an Angular Data Grid
http://ui-grid.info
MIT License
5.39k stars 2.47k forks source link

Selected row count in grid footer not updated when rows deleted programmatically #4100

Open louspringer opened 9 years ago

louspringer commented 9 years ago

Deleting gird rows with gridOptions.data.splice does not update girdFooter selected row counts.

See http://plnkr.co/edit/a7GogUdI5nDUvc2KN1Rt?p=preview

Example is a fork of Tutorial: 210 Selection.

$scope.deleteSelected = function() {
      var rowsToDelete;
      rowsToDelete = $scope.gridApi.selection.getSelectedRows();
      if (rowsToDelete.length) {
        rowEntity = rowsToDelete[0];
        rowIndexToDelete = $scope.gridOptions.data.indexOf(rowEntity);
        $scope.gridOptions.data.splice(rowIndexToDelete, 1);
      }
   }

Steps to reproduce

  1. select row
  2. press 'Delete selected row' button, which fires $scope.deleteSelected
  3. footer still indicates deleted row is selected (selected row count does not decrement)

    Before

plunker

After

plunker

thynctank commented 8 years ago

I've found you may need to set gridOptions.totalItems manually after a few different issues with our instance - using external sort, sorting, deleting rows and external filter all had this issue.

You may also need to wrap your assignment in a $timeout because ui-grid does set the numbers, just not to the gridApi.grid.renderContainers.body.renderedRows.length I was expecting.