Dynamically Expand Subgrid in a loop - JQGrid

↘锁芯ラ 提交于 2019-12-02 03:39:25
Oleg

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.

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