jqGrid with multiselect如何在加载时检查所有复选框和顶部复选框?

时间:2010-01-08 15:51:30

标签: jquery jqgrid

如何在实例化时指示jqGrid直接选中所有复选框?这可以作为colModel中的参数以某种方式完成吗?

4 个答案:

答案 0 :(得分:1)

我尝试了上面的解决方案但不会选中复选框。这解决了这个问题。

$('.cbox').trigger('click').attr('checked', true);

修复了复选框的问题,您只需点击一次即可取消选中。

确保在加载jqgrid后执行此操作。

答案 1 :(得分:0)

您可能想看一下setSelection。来自jqGrid Documentation

setSelection(rowid, onsetselection)
Toggles a selection of the row with id = rowid; if onsetselection is true (the default) then the event onSetRow is launched, otherwise it is not 

另一种方法是在网格中标记所有复选框:

$('.cbox').click();

但是你想在网格完成后调用它,所以在gridComplete事件中调用它:

    gridComplete: function() {
      $('.cbox').click();
    }

答案 2 :(得分:0)

这是一个将选择所有行的函数。它遵循丹尼尔提出的许多相同建议:

gridSelectAll : function(divID){
    // Select header checkbox (no jqGrid API for this, unfortunately)
    var parentView = divID.replace("#", "#gview_");
    jQuery(parentView).find("#cb_jqg").click();

    // Loop again to select all rows
    var data = jQuery(divID).getDataIDs();
    for(var i=0; i < data.length;i++){
        jQuery(divID).setSelection(data[i]); // All selected by default
    }
}

您可以从GridComplete事件中调用此方法,以便在加载时自动检查所有方框。

答案 3 :(得分:0)

我试过了

$('.cbox').click();
gridComplete中的

但是没有用。然后我尝试了这个:

$('.cbox').attr('checked', true);

并且工作正常,它将所有复选框设置为已选中,但发生的情况是我需要单击两次以取消选中一个。

对我有用的是:

$('.cbox').trigger('click');
相关问题