jQuery - jQGrid - expand,collapse subgrid on grid row click

mirku picture mirku · Nov 27, 2010 · Viewed 18.7k times · Source

Here there is an answer on how to expand a subgrid when we click a row using:

onSelectRow: function(rowId) {
    $("#jqgrid_id").expandSubGridRow(rowId);
}

How can we collapse the row if it has been already expanded? I am looking for something like:

onSelectRow: function(rowId){ 
    if (the_row_of_the_grid is expanded) {
        // collapse: How implement this???
    } else {
        $("#jqgrid_id").expandSubGridRow(rowId);
    }
}

to have a complete expand/collapse on row click.

Answer

Oleg picture Oleg · Nov 27, 2010

I haven't tested it, but it seems to me that the following code should do what you need:

onSelectRow: function (rowId) {
    $("#jqgrid_id").jqGrid ('toggleSubGridRow', rowId);
}

(see jqGrid documentation)