Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS ui网格行选择限制_Angularjs_Ui Grid - Fatal编程技术网

AngularJS ui网格行选择限制

AngularJS ui网格行选择限制,angularjs,ui-grid,Angularjs,Ui Grid,我想将ui网格中的选择限制为10。 在我的gridOptionsI中 onRegisterApi: function (gridApi) { $scope.gridApi = gridApi; gridApi.selection.on.rowSelectionChanged($scope, function (row) { $scope.rowsSelected = $scope.gridApi.selection.getSelectedRows();

我想将ui网格中的选择限制为10。 在我的
gridOptions
I中

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

但是现在我不知道如何禁用这个选项。。。谢谢你的帮助

一个可能的解决方案,尽管有点晚:

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

面临相同的问题。你修好了吗?