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
howto disable selection in ng-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 false
from beforeSelectionChange
to disable changing the selected rows on the grid.
是的,你可以返回false
从beforeSelectionChange
到禁止改变对电网的选定行。
$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;
}