javascript 如何禁用 ng-grid 中的选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19688400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 16:29:17  来源:igfitidea点击:

howto disable selection in ng-grid

javascriptangularjsangular-uing-grid

提问by Tim

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.

是否可以使用内置功能“禁用”或锁定 ng-grid 的选择?我希望用户能够选择一行,单击一个按钮,然后网格将保持锁定状态,直到用户按下另一个按钮。

回答by user508994

Yes, you can return falsefrom beforeSelectionChangeto disable changing the selected rows on the grid.

是的,你可以返回falsebeforeSelectionChange到禁止改变对电网的选定行。

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

HTML:

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>
<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

示例代码:http: //plnkr.co/edit/PbhPzv?p=preview

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

另见:https: //github.com/angular-ui/ng-grid/wiki/Configuration-Options

回答by David Dehghan

This works in Angular 2.3:

这适用于 Angular 2.3:

  constructor() {
    this.gridOptions = <GridOptions>{};
    this.gridOptions.suppressCellSelection = true;
  }