I'm currently working with JQuery plugin for struts2. I would like to know how to reload a JQuery grid without loosing the current scroll position and collapse rows.
In order to reload the data in the grid I'm using the following javascript code:
var timerID = setInterval("RefreshGridData()", 5000);
function RefreshGridData() {
$("#griditems").trigger("reloadGrid");
}
The jsp of the grid is the following:
<s:url id="itemsurl" action="getItemsJson.action" />
<s:url id="subitemsurl" action="getSubItemsJson.action" />
<sjg:grid id="griditems" caption="Items and Subitems" dataType="json"
href="%{itemsurl}" pager="false" viewrecords="true" height="400"
gridModel="gridModel" rowNum="-1" sortable="true">
<sjg:grid id="gridsubitems" subGridUrl="%{subitemsurl}"
gridModel="gridModel" rowNum="-1">
<sjg:gridColumn name="subcol1" index="subcol1" title="SubColumn 1"
width="120" />
<sjg:gridColumn name="subcol2" index="subcol2" title="SubColumn 2"
align="left" width="120" />
</sjg:grid>
<sjg:gridColumn name="col1" index="col1" title="Column 1" sortable="true"
width="80"/>
<sjg:gridColumn name="col2" index="col2"
title="Column 2" sortable="true" />
<sjg:gridColumn name="col3" index="col3" title="Column 3"
sortable="true" />
</sjg:grid>
Any comments on how to implement this are welcome.
Thanks in advance.
after data is loaded in event loadComplete
EDIT :
not sure if this will work i didn't test it tut it should be something like that
EDIT
setGridParam - not suire if it will work on events but you might try that
i couldn't find how to attach subGridRowExpanded topick using tag library in struts but try changing config after grid is constructed by taglibrary
EDIT
ok different aproach :
and when load of grid is complete :
I've solve the problem by adding this
this code keep the last position of grid
I finally solved my problem. Thanks to the useful information provided by firegnom in his answer and comments I got a big push forward to create an implementation of a jQuery grid (with subgrid), using Struts2 tags, which keeps its previous scroll position and expanded/collapsed state after reloading it.
JavaScript
I used the isDigit function because the first element found with class sgexpanded is always 0 and that is not a valid row number in a grid since rows start counting from 1. Another observation is that I set a timer before calling the setScrollPos function because my grid doesn't have a scroll bar before a certain number of rows are expanded, and since the expanding effect is not immediate, it's necessary to set the scroll position after a certain time.
Grid tags code
Hope it helps somebody.
Cheers.
To load the page in-place (which keeps curent scroll position) simply use: