Wednesday, 28 September 2011

Keep view position between (x)pages

By default xpages doesnot keep the position of the view (pageno.) when going to another page. So when you go back to the view page from another page, the view will display from the first entry (and page) again. Not very userfriendly if you had just left it from page 3.
You will have to make the view page remember its position by storing the number of the first row on the page in a scoped variable.
In the "beforeRenderResponse" event add the following code:

   var c = getComponent("viewPanel");
   if (c) {
, c.first);
"viewPanel" is the id of your view control of course.
And in the view control's All properties - first - add the code:

   var vwFirst = sessionScope.get("viewFirst"+view.getPageName());
   if (vwFirst) return vwFirst;

This will also work when displaying data tables through a repeat control.

Used sources: 



Anonymous said...

You can also use the PagerState control in the Extension Library to do the same thing.

Vitor Pereira said...

How is the sessionScope variable updated when you use the pager?

Tom Steenbergen said...

The pager control does a full update, so the beforeRenderResponse is executed on every page change.

Mirek Navratil said...

The pager control does either full or partial update. The proposed solution only works with the full update.
Any idea how to make it work with partial update?

quintiexxx said...

tried this on a repeat control but indeed, I need to perform a full update on it in order to have it working..