0

Store and Restore Scrollpositions of ZK-Components

asked 2009-11-03 08:30:28 +0800

robertpic71 gravatar image robertpic71
1275 1

Is there a way to store the actual scrollposition and restore this position later?

Example:

My cataloge.

- scroll down to the bottom an click to any picture [1]
- use the backbutton form the browser [2]

--> you will return to the overview, but the scroll position is on top

I want to store the scrollposition [1]
and restore it [2]

and [3]: Home/Startscreen button will clear the scroll-cache

Is there any way to do that?

I use Borderlayout. The content is in the center inside the html-component.

Any ideas?

/Robert

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2009-11-08 19:49:49 +0800

tmillsclare gravatar image tmillsclare
799 2 5 29

Hey Robert,

This is currently not implemented yet, what I have done is added it to the feature requests on sourceforge. You can find it here!

Thanks,
Tim

link publish delete flag offensive edit

answered 2009-11-09 01:24:56 +0800

robertpic71 gravatar image robertpic71
1275 1

Hi Tim.

Thanks for your answer and featurerequest. I've done some tests with clientcoding (scrollTop, srollLeft).

I think, i will migrate to ZK5 first - client coding seems to be smarter there :-)

However, actually my cataloge do not work with ZK5RC: no tree and no error to see :-(

/Robert

link publish delete flag offensive edit

answered 2009-11-09 23:08:22 +0800

erlen gravatar image erlen
78

Here's a technique I used that might work for you. Note: I have only tested this in ZK 3.6.2, I don't think it works in ZK 5. In my case I had a tree object. Clicking on a treerow was supposed to update a window sitting next to the tree. Without this technique, if the tree was scrolled down a bit then when the window updated it pushed the scroll bar back to the top...very annoying.

So instead of writing a normal onclick event listener to do my window update, for each treerow (tr) I did

    String uuid=tr.getTree().getUuid()+"!body";
    tr.setAction(
      "onclick: var t=document.getElementById('"+uuid+"');"+
      "comm.sendUser('"+tr.getUuid()+"', t.id, t.scrollTop);"
    );  

and then I wrote an onuser EventListener, and applied it to each treerow:

  private static EventListener onUserListener =
    new EventListener () {
      public void onEvent (Event ev) throws Exception {
        String []data=(String[]) ev.getData();
        String tableBodyId=data[0];
        String scrollTop=data[1];
        if (new Integer(scrollTop).intValue()>0)
          // restore original scrollTop value
          Clients.evalJavaScript("var t=document.getElementById('"+tableBodyId+"');t.scrollTop="+scrollTop+";");
      }
    };

The key was knowing which uuid value to use in order to grab the scrollTop value; I figured it out by using Firebug and a bit of trial and error testing. Tested ok with FF 3.5, and IE 6, 7, 8. Did not test any others.

link publish delete flag offensive edit

answered 2009-11-10 01:13:58 +0800

robertpic71 gravatar image robertpic71
1275 1

Big thanks Elen,

i'll check this out today.

/Robert

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-11-03 08:30:28 +0800

Seen: 598 times

Last updated: Nov 10 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More