AngularJS UI网格行选择限制 [英] AngularJS ui-grid row select limit

查看:100
本文介绍了AngularJS UI网格行选择限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将ui-grid中的选择限制为10个. 在我的gridOptions中,我

I want to limit the selection in my ui-grid to 10. In my gridOptions I do

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

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

but now I don't know how to disable this option... thanks for any help!

推荐答案

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

A possible solution, albeit a bit late:

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行.

When the rowSelectionChanged event is triggered, the row has already been selected, and the selectedCount has been updated. If you want a maximum of 10 selected rows, we need to deselect the current row when there are more than 10 rows selected.

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

这篇关于AngularJS UI网格行选择限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆