AngularJS ui-grid行选择限制

时间:2016-09-01 12:20:25

标签: angularjs ui-grid

我想将我的ui-grid中的选择限制为10。 在我的onRegisterApi: function (gridApi) { $scope.gridApi = gridApi; gridApi.selection.on.rowSelectionChanged($scope, function (row) { $scope.rowsSelected = $scope.gridApi.selection.getSelectedRows(); $scope.countRows = $scope.rowsSelected.length; if ($scope.countRows === 10) { // disable option to select rows now } }); } 我做

{{1}}

但现在我不知道如何禁用此选项...感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

可能的解决方案,尽管有些迟:

onRegisterApi: function (gridApi) {
    $scope.gridApi = gridApi;
    gridApi.selection.on.rowSelectionChanged($scope, function (row) {
        $scope.rowsSelected = $scope.gridApi.selection.getSelectedRows();
        $scope.countRows = $scope.rowsSelected.length;
        if ($scope.countRows > 10)
        {
            row.setSelected(false); // Remove selection for the current row
        }
    });
}

触发rowSelectionChanged事件时,已经选择了该行,并且selectedCount已更新。如果最多要选择10行,那么当选择的行超过10条时,我们需要取消选择当前行。

还要确保$scope.gridOptions.enableSelectionBatchEvent = false