jqGrid with multiselect如何在加载时检查所有复选框和顶部复选框?
如何在实例化时指示jqGrid直接选中所有复选框? 这可以作为colModel中的参数以某种方式完成吗?
我尝试了上面的解决方案,但它不会选中复选框。 这解决了这个问题。
$('.cbox').trigger('click').attr('checked', true);
修复了复选框的问题,您只需单击一次即可取消选中。
确保在加载jqgrid后执行此操作。
您可能想看看setSelection。 来自jqGrid文档
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(); }
我试过了
$('.cbox').click();
在gridComplete
但是没有用。 然后我尝试了这个:
$('.cbox').attr('checked', true);
这工作,它设置所有复选框,但发生了什么,我需要点击两次取消选中一个。
对我有用的是:
$('.cbox').trigger('click');
这是一个将选择所有行的函数。 它遵循丹尼尔提出的许多相同建议:
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事件中调用此方法,以便在加载时自动检查所有框。