tags:

views:

873

answers:

3

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
The $('.cbox').click(); sounded great but it doesn't work.
Nyla Pareska
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
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
$('.cbox').click() and $('.cbox').trigger('click') should do the same thing.
Daniel Moura
Have you tried my solution?
Justin Ethier
@Daniel, I tried your solution but for some reason that did not work. Do not know why.
Nyla Pareska