2

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.

Community
  • 1
  • 1
mirku
  • 79
  • 1
  • 4
  • 8

3 Answers3

7

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)

Jess Stone
  • 677
  • 8
  • 21
Oleg
  • 220,925
  • 34
  • 403
  • 798
2

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);
}
chasew
  • 8,438
  • 7
  • 41
  • 48
1

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 :)

Ro Siade
  • 399
  • 3
  • 5