Dynamically Expand Subgrid in a loop - JQGrid

后端 未结 1 1610
难免孤独
难免孤独 2021-01-24 15:00

I have Grid with a subgrid using subGridRowExpanded.

And I want to dynamically expand some rows of the grid so I wrote following in GridComplete Event of First Grid. id

1条回答
  •  一生所求
    2021-01-24 15:12

    If I understand you correct you have very close problem as discussed in the answer. What you try to do seems the same what expandOnLoad: true property of the subGridOptions option should do. Like I described in the answer jqGrid don't support queuing of Ajax requests. If you execute

    $("#myGridName").expandSubGridRow(ids[0]);
    

    with remote datatype or subgridtype ('json' or 'xml') the Ajax request will be sent to the server. Till we receive the corresponding response from the server the internal property

    $("#myGridName")[0].grid.hDiv.loading
    

    will be set to true and all other Ajax requests for example from $("#myGridName").expandSubGridRow(ids[1]) will be just skipped (ignored).

    The same problem (bug) exist in the current implementation of expandOnLoad: true. If you open in the official jqGrid demo the "Hierarchy (4.0) new" tree node and then look at the demo "Expand all Rows on load" you will see that not all rows are correctly expanded as promised (you have to scroll the grid to see all subgrids).

    I think that to implement expanding of subgrids on load correctly you should do about the following

    • You should examine the list of collapsed subgrids (the corresponding row has class "sgcollapsed") and expand only the first found subgrid.
    • The expanding of the next subgrid should be done only after the response from the server will be received and processed.

    I can recommend you to use success callback function of ajaxSubgridOptions jqGrid options because there are no loadComplete event after loading the subgrid. The current implementation of the Ajax request in subgrid uses complete callback function of jQuery.ajax (see here) which will be called before success callback. So you can define your success callback as the method of the ajaxSubgridOptions option of jqGrid. Inside of the success callback you can call $("#myGridName").expandSubGridRow(ids[i]) for the next node (if any still not expanded). In the way you can open all subgrids.

    To enumerate subgrids more effectively the answer could be helpful for you.

    0 讨论(0)
提交回复
热议问题