Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

howto disable selection in ng-grid

Is it possible to "disable" or lock the selection of a ng-grid using the inbuilt functionality? I want the user to be able to select a row, click a button and then the grid will stay locked until the user presses another button.

like image 769
Tim Avatar asked Oct 30 '13 16:10

Tim


2 Answers

Yes, you can return false from beforeSelectionChange to disable changing the selected rows on the grid.

$scope.option = {
    enableRowSelection: true,
};
$scope.gridOptions = {
    data: 'myData',
    beforeSelectionChange: function() {
      return $scope.option.enableRowSelection;
    }
    //, ...
};

HTML:

<button ng-click="option.enableRowSelection=false">Freeze Selection</button>
<button ng-click="option.enableRowSelection=true">Unfreeze Selection</button>
<div class="gridStyle" ng-grid="gridOptions"></div>

Example Code: http://plnkr.co/edit/PbhPzv?p=preview

See also: https://github.com/angular-ui/ng-grid/wiki/Configuration-Options

like image 105
user508994 Avatar answered Oct 01 '22 20:10

user508994


This works in Angular 2.3:

  constructor() {
    this.gridOptions = <GridOptions>{};
    this.gridOptions.suppressCellSelection = true;
  }
like image 42
David Dehghan Avatar answered Oct 01 '22 20:10

David Dehghan