I have a find function on a webgrid. When a row is selected based on the find criteria, I want that row to "jump" to the top of the grid, i.e. become the first row displayed. I am using scrollToView() but that only puts the row at the bottom of the grid.
Any pointers?
Kenneth
Hello Kenneth,
I am afraid there is not an easy way. I assume you are using the scrollToView() for the first cell of the row, but the way this method is implemented -- the scroll will be to bottom and not to top.
The easiest solution I can think of at this point is to get the actual DOM Html Element of the row or cell using row.Element / cell.Element and then manually calculate its position and scroll the page to it. Will require some javascript, though.
For calculating the position of an DOM Html element you can use a library like jQuery or use a simple function as described here:
http://www.quirksmode.org/js/findpos.html
To scroll the page to a specified location, you can use the following script
http://www.mediacollege.com/internet/javascript/page/scroll.html
Hope this helps.