Dynamically Expand Subgrid in a loop - JQGrid

陌路散爱 提交于 2020-01-11 11:50:05

问题


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. ids is array of row ids of my Grid

for(int i =0; i< ids.length; i++) {
    //Checking with condition
    $("#myGridName").expandSubGridRow(ids[i]);
}

I also tried with following code, But for some reason checkboxes in GridComplete of second level, is added only for last expanded row.

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

Above code expands appropriate rows. But,

In GridComplete event of Subgrid, I've check boxes in each row.

So, Here I need to check some of the Chekc boxes.

But the Problem is,

The subgrid_row_id is getting wrong

i.e. ID of last subgrid to be expanded is assigned in SubGridRowExpanded of Parent Grid.

Note : I manually adding checkboxes to each row in subgrid

Thanks in Advance.


回答1:


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.



来源:https://stackoverflow.com/questions/8046774/dynamically-expand-subgrid-in-a-loop-jqgrid

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