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

一曲冷凌霜 提交于 2019-12-10 10:54:33

问题


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.


回答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)




回答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);
}



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



来源:https://stackoverflow.com/questions/4291819/jquery-jqgrid-expand-collapse-subgrid-on-grid-row-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!