views:

813

answers:

1

Setup: I have a Struts web application where I use displaytag elements to do all of my table work. Each column is sortable.
Situation: When I click sort, on a long page, it sorts, but drops you at the top of the page.
Question: How do I use an anchor or some other method to come back to the table rather than the top of the page.

Addition: I have looked at ajax-tags:display to wrap the display:table tag, but would like to attempt to do this with just what I have already (html anchors maybe?) rather than including another dependency.

A: 

This was a whole lot easier than I first thought. All you need to do is set the requestURI of each display:table tag to # and the id of the table.

For example

<display:table name="tablename" id="tableid" sort="list" requestURI="" export="true">

Changed to

<display:table name="tablename" id="tableid" sort="list" requestURI="#tableid" export="true">
Tiggerizzy
Do you have to add anchors yourself, or does the browser just somehow automagically scroll to those ids?
MetroidFan2002
It actually does "automagically" scroll to those ids. I was really surprised when it happened the first time. I am thinking that you can point to any id on the page.
Tiggerizzy