3

我想将我的 ui-grid 中的选择限制为 10。在我的gridOptions我做

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
        }
    });
}

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

4

1 回答 1

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.

于 2018-10-01T10:23:01.880 回答