mirku
mirku

Reputation: 79

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

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.

Upvotes: 2

Views: 19610

Answers (3)

Ro Siade
Ro Siade

Reputation: 399

it wasn't working for me at first xD... I've set selectOnExpand on my subGridOptions, so every time I click an expand it select the row and call onSelectRow once again ahaha... so funny...

Hope this help some fool like me there :)

Upvotes: 1

Oleg
Oleg

Reputation: 221997

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)

Upvotes: 7

chasew
chasew

Reputation: 8828

i needed the same thing, but i couldn't permit the grid to be expanded in the case where it was already collapsed, so the 'toggleSubGridRow' wouldn't work for me. Better in the situation where only a collapse should be permitted is the 'collapseSubGridRow' method.

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

Upvotes: 2

Related Questions