how to disallow selection with beforeSelectionChange for select All chekbox selection in ng-grid

北城余情 提交于 2019-12-13 06:24:24

问题


The beforeSelectionChange is being called with an rowItem array while clicking the select All checkbox in the header, no option to disallow selection. I have a requirement to disabled the checkbox for some row depending upon model. I can do it with CheckboxCellTemplate with configuring ng-disabled. But i want the disabled row not be selected when clicking on select all checkbox. Is there a way to do it?

Thanks


回答1:


Got this one fixed with the below solution, please let me know if you have a better solution or you see any issue with this.

  $scope.myGridOptions = {
    data: 'gridData',
    enableSorting: false,
    showSelectionCheckbox: true,
    selectedItems: $scope.selectedData,
    selectWithCheckboxOnly: true,
    afterSelectionChange: function (rowItem) { return $scope.updateRowSelection(rowItem); }};


$scope.updateRowSelection = function (rowItem) {
    if (rowItem.length) {
        for(var i = 0 ; i < rowItem.length ; i ++ ) { //Foreach can be used
            if (!$scope.isMySelectionAllowed(rowItem[i].entity)){
                if (rowItem[i].selected) {
                    $scope.myGridOptions.selectRow(rowItem[i].rowIndex, false);
                }
            }
         }
    }
};


来源:https://stackoverflow.com/questions/21610945/how-to-disallow-selection-with-beforeselectionchange-for-select-all-chekbox-sele

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!