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

18,891

Solution 1

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)

Solution 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);
}

Solution 3

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

Share:
18,891
mirku
Author by

mirku

Updated on June 05, 2022

Comments

  • mirku
    mirku almost 2 years

    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.