循环动态展开子网格 - JQGrid
我有一个带有使用 subGridRowExpanded 的子网格的网格。
我想动态扩展网格的一些行,所以我写了以下内容 在第一个网格的 GridComplete 事件中。 ids 是我的网格的行 id 数组
for(int i =0; i< ids.length; i++) {
//Checking with condition
$("#myGridName").expandSubGridRow(ids[i]);
}
我也尝试使用以下代码,但由于某种原因,第二级 GridComplete 中的复选框仅添加到最后一个扩展行。
$("#myGridName").expandSubGridRow(ids[0]);
$("#myGridName").expandSubGridRow(ids[1]);
上面的代码扩展了适当的行。但是,
在 Subgrid 的 GridComplete 事件中,我在每一行中都选中了复选框。
所以,在这里我需要检查一些 Chekc 框。
但问题是,
subgrid_row_id 出错
,即最后一个要扩展的子网格的 ID 被分配在父网格的 SubGridRowExpanded 中。
注意:我手动将复选框添加到子网格中的每一行,
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解你是正确的,你有非常接近的问题,如 答案< /a>.您尝试做的事情似乎与 expandOnLoad: truesubGridOptions 选项的 a> 属性应该可以。就像我在答案中描述的那样,jqGrid不支持排队Ajax 请求。如果您
使用远程
datatype
或subgridtype
('json' 或 'xml')执行,Ajax 请求将发送到服务器。在我们收到服务器的相应响应之前,内部属性将设置为
true
以及所有其他 Ajax 请求,例如来自$("#myGridName").expandSubGridRow(ids[1])
将被跳过(忽略)。expandOnLoad: true
的当前实现中也存在同样的问题(bug)。如果您在官方 jqGrid 演示中打开“Hierarchy (4.0) new”树节点然后查看演示“加载时展开所有行”,您将看到并非所有行都按照承诺正确展开(您必须滚动网格才能看到所有子网格)。我认为要正确实现加载时子网格的扩展,您应该执行以下操作
我建议您使用
ajaxSubgridOptions
jqGrid 选项的success
回调函数,因为加载子网格后没有loadComplete
事件。当前子网格中 Ajax 请求的实现使用 jQuery 的complete
回调函数。 ajax (参见此处)将在success
回调之前调用。因此,您可以将您的success
回调定义为 jqGrid 的ajaxSubgridOptions
选项的方法。在success
回调内部,您可以为下一个节点(如果有任何尚未展开的节点)调用$("#myGridName").expandSubGridRow(ids[i])
。这样你就可以打开所有子网格。更有效地枚举子网格答案 可能对你有帮助。
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 executewith remote
datatype
orsubgridtype
('json' or 'xml') the Ajax request will be sent to the server. Till we receive the corresponding response from the server the internal propertywill 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
I can recommend you to use
success
callback function ofajaxSubgridOptions
jqGrid options because there are noloadComplete
event after loading the subgrid. The current implementation of the Ajax request in subgrid usescomplete
callback function of jQuery.ajax (see here) which will be called beforesuccess
callback. So you can define yoursuccess
callback as the method of theajaxSubgridOptions
option of jqGrid. Inside of thesuccess
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.