jqgrid自动刷新子网格问题
目前我使用此代码来刷新网格:
setInterval(function(){ jQuery("#grid").trigger("reloadGrid"); },10000);
它运行良好。但我需要一个扩展子网格的解决方案。当网格刷新时,扩展的子网格将关闭。
有没有办法在不关闭展开的子网格的情况下刷新网格?
Currently I use this code for refreshing the grid:
setInterval(function(){ jQuery("#grid").trigger("reloadGrid"); },10000);
It works well. But I need a solution for expanded subgrids. When the grid refreshed the expanded subgrids are closing.
Is there any way to refresh the grid without close the expanded subgrids?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个老问题,但我也遇到过同样的问题,所以我想我应该分享一下我所做的事情。 Eonasdan 的回答是正确的。就我而言,我向 subGridRowExpanded 和 subGridRowCollapsed 事件添加了代码,以存储已展开的行的行 ID(我只允许一次展开一行,但您也可以使用集合)。然后,我向表的 loadComplete 事件添加了代码,以重新打开回发后折叠的行。这部分很明显,但这里有两个问题:
1. 重新扩展子网格不会导致其数据因某种原因而被持久化。所以我必须返回服务器才能获取它。我通过重新提交子网格行(它具有网格 id、下划线和 rowid)来做到这一点。
2. 由于某种原因,您必须使用计时器并在延迟后扩展子网格(即使 1ms 似乎也可以)。就像您无法在 loadComplete 事件本身期间扩展网格,但如果您等待一个时间,那么它就可以正常工作。
像这样:
This is an old question but I struggled with the same thing so I thought I'd share what I did. Eonasdan's answer is right on. In my case I added code to the subGridRowExpanded and subGridRowCollapsed events to store the row ID of the row which have been expanded (I only allowed one row to be expanded at a time, but you could use a collection as well). Then I added code to the loadComplete event for the table to re-open the row that collapsed after the postback. That part is all obvious, but here are the two kickers:
1. Re-expanding the subgrid doesn't cause its data to be persisted for some reason. So I had to go back to the server to get it. I did that by resubmitting the subgrid row (which has an id of the grid an underscore and the rowid).
2. For some reason you have to use a timer and expand the subgrid after a delay (even 1ms seems to work). It is like you can't expand the grid during the loadComplete event itself, but if you wait a tick then it works fine.
So like this:
看起来他们的演示页面正在将 TR 类从sgcollapsed 为 sgexpanded。我认为你可以在刷新之前保留一组打开的 TR,并在刷新之后重新打开它们。
我对 jqGrid 知之甚少,但我想我应该发布这个,因为它似乎从聊天中为您指明了正确的方向。
looks like their demo page is changing the TR class from sgcollapsed to sgexpanded. I would think you could keep an array of TRs that are open before the refresh and re-open them after.
I know very little about jqGrid, but I thought I would post this as it seemed to point you in the right direction from the chat.