How can I instruct jqGrid to directly select all checkboxes when I instantiate it? Can this be done as a parameter in the colModel somehow?
A:
You may want to take a look at setSelection. From 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
Another way you can do this is by marking all checkboxes int the grid:
$('.cbox').click();
But you want to call this after the grid is complete, so call it inside gridComplete event:
gridComplete: function() {
$('.cbox').click();
}
Daniel Moura
2010-01-08 17:51:08
The $('.cbox').click(); sounded great but it doesn't work.
Nyla Pareska
2010-01-11 07:27:34
A:
Here is a function that will select all rows. It follows many of the same suggestions made by Daniel:
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
}
}
You can call this from the GridComplete event to automatically check all of the boxes at load time.
Justin Ethier
2010-01-08 20:59:15
A:
I tried the
$('.cbox').click();
in the gridComplete
but that didn't work. Then I tried this:
$('.cbox').attr('checked', true);
and that worked, it set all checkboxes to checked but what happened then is that I needed to click twice to uncheck one.
What worked for me was:
$('.cbox').trigger('click');
Nyla Pareska
2010-01-11 08:26:59
$('.cbox').click() and $('.cbox').trigger('click') should do the same thing.
Daniel Moura
2010-01-11 14:06:27
@Daniel, I tried your solution but for some reason that did not work. Do not know why.
Nyla Pareska
2010-01-12 06:59:16