jqgrid - Disable Header Check box (multiselect = true) if all rows are disable

隐身守侯 提交于 2020-05-09 17:17:32

问题


Using jqgrid with multiSelect="true" option. I am disabling rows and prevent its selection based on some flag status as mentioned below

Disable row(s) based on IS_FLAGGEd = 1

//disable row which are flagged
        rowattr: function (item) {
                if (parseInt(item.IS_FLAGGED) == 1) {
                    return {"class": "ui-state-disabled ui-jqgrid-disablePointerEvents"};
                }
        },

        //prevent selection of disabled rows
        beforeSelectRow: function (rowid, e) {
            if ($(e.target).closest("tr.jqgrow").hasClass("ui-state-disabled")) {
                return false;   // not allow select the row
            }
            return true;    // allow select the row
        }

To disable header checkbox, implemented below code, but it disables the header check box even if one row is disabled.

//disable header checkbox only if all rows are disabled        
        loadComplete: function() {
            var grid = $("#grid");
            var ids = grid.jqGrid('getDataIDs');
            for(var i=0;i < ids.length;i++){
                var rowId = ids[i];
                var rowData = jQuery('#grid').jqGrid ('getRowData', rowId);
                console.log(rowData.SUBMIT_TO_ACC);
                 if(rowData.FLAG_STATUS == 1){
                    $('tr.ui-jqgrid-labels').addClass('ui-state-disabled ui-jqgrid-disablePointerEvents');
                }
            }
        }

How can I disable Header Check box (multiselect = true), only when ALL rows are disabled i.e hasClass(ui-state-disabled) ?

jQgrid version = 4.6
jQuery version = 1.7.2


回答1:


I would suggest you to save the information whether all row are disabled or not inside of your custom option of jqGrid. The corresponding code could be like on the demo http://jsfiddle.net/OlegKi/aagxejj5/44/ which uses

rowattr: function (item, rd, rowid) {
    var p = $(this).jqGrid("getGridParam");
    if (rd.closed === "true" || rd.closed === true) {
        return {"class": "ui-state-disabled ui-jqgrid-disablePointerEvents"};
    } else {
        p.isSomeEnabled = true;
    }
},
beforeRequest: function () {
    var p = $(this).jqGrid("getGridParam");
    p.isSomeEnabled = false; // reset for the filling
},
loadComplete: function () {
    var p = $(this).jqGrid("getGridParam"), $selAll = $("#cb_" + this.id);

    if (p.isSomeEnabled) {
        $selAll.removeClass("ui-state-disabled ui-jqgrid-disablePointerEvents");
        $selAll.click(); // select all
        // one need to trigger the click twice only because of bugs
        // in case of usage old jQuery version
        $selAll.click(); // select all
        $selAll.prop("checked", true);
    } else {
        $selAll.addClass("ui-state-disabled ui-jqgrid-disablePointerEvents");
        $selAll.prop("checked", false);
    }
}

I placed one enabled on the second page, so one can switch the pages and see that the above code correctly work.




回答2:


The checkbox in the header has the id which is combined from the "cb_" prefix and the grid id. So you can hide the element with

var myGrid = $("#list"); $("#cb_"+myGrid[0].id).hide();



来源:https://stackoverflow.com/questions/30565702/jqgrid-disable-header-check-box-multiselect-true-if-all-rows-are-disable

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