限制ng-grid中所选项目的数量(Limit number of selected items in ng-grid)
有没有办法限制ng-grid中所选项目的数量?
我没有找到设置来做到这一点,所以我试图使用
watchCollection
中的gridOptions.selectedItems
来阻止它。当
selectItems
的length
大于5时,我尝试取消选择最后一个选择但是没有按预期工作,因为项目行索引似乎与呈现的不同:这是观察者代码:
$scope.$watchCollection('gridOptions.selectedItems', function (newVal, oldVal) { if ($scope.gridOptions.selectedItems.length > 5) { for (var i = 0; i < $scope.importableFilesData.length; i++) { if ($scope.importableFilesData[i] === newVal[0]) { $scope.gridOptions.selectRow(i, false); } } }
Is there a way to limit the number of selected items in ng-grid?
I did not find a setting to do that, so I am trying to prevent it using a
watchCollection
ingridOptions.selectedItems
.When the
length
ofselectItems
is greater than 5, I try to deselect the last selection but is not working as expected because the item row index seems to be different as rendered:This is the watcher code:
$scope.$watchCollection('gridOptions.selectedItems', function (newVal, oldVal) { if ($scope.gridOptions.selectedItems.length > 5) { for (var i = 0; i < $scope.importableFilesData.length; i++) { if ($scope.importableFilesData[i] === newVal[0]) { $scope.gridOptions.selectRow(i, false); } } }
原文:https://stackoverflow.com/questions/32471288