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开发者_如何学JAVA the grid refreshed the expanded subgrids are closing.
Is there any way to refresh the grid without close the expanded subgrids?
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:
var expandSubGrid = function(){
$('#grid').jqGrid('expandSubGridRow', expandedRowID);
$('#grid_' + expandedRowID).trigger('reloadGrid');
};
//the loadComplete event handler which was wired up when I created the grid
var grid_loadComplete = function () {
//expand the subgrid
window.setTimeout(expandSubGrid, 1);
};
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.
精彩评论