0

I have a table which needs to be scrollable within a single page. I've used a jQuery scrollable table plugin to accomplish this but now I need to figure out how to scroll to a specific row.

I've tried a few different methods including:

$.scrollTo($('#rowIWantToScrollTo'));

and

var rowpos = $('#rowIWantToScrollTo').position();

$('#myTable').scrollTop(rowpos.top);

and

$('#rowIWantToScrollTo').scrollIntoView();

And nothing has worked so far.

4
  • What jQuery scrollable table plugin did you use? Perhaps, it has the functionality you are looking for. Commented Apr 5, 2012 at 1:47
  • The one called jquery scrollable table plugin and it doesn't contain the functionality. Is there one you know of that does? Commented Apr 5, 2012 at 2:01
  • No I don't. Just trying to see if I can be of any help. Is it this one that you are using?. Commented Apr 5, 2012 at 2:10
  • Yup.. that's the one I'm using. Commented Apr 5, 2012 at 2:13

2 Answers 2

1

LIVE DEMO

Here's how to do it. (You were close).

1) Fetch top offset of element using offset() and .top

2) Scroll to element using ScrollTo

I broke it up a bit for illustration purposes.

Javascript:

$("a").click(function(e){

  var _offset = $(".row9").offset();
  var _topoffset = _offset.top;

  $(".scrollbox").scrollTop(_topoffset);

  e.preventDefault();
});
Sign up to request clarification or add additional context in comments.

3 Comments

Doesn't work nor does the example you linked to work in Chrome or IE8.
It actually does work. It appears jsfiddle reset it to use "MooTools" and not "jQuery". I've updated it to jQuery and you can check the updated demo to confirm: jsfiddle.net/8AYvW/2
Weird. I had changed it back to jQuery and it still didn't work but your updated demo works great.. thanks!
0

Yes, you are right @ShaneCourtrille. From what I can see, there is no functionality inbuilt in the plugin to scroll to a particular row.

Below is a very simple solution using hyperlinks. Not sure if this is what you want, but it does the job...

Create an internal anchor like this...

<tr>
    <td><a name="toHere"></a>FL</td>
    <td>$1,364.27</td>
    <td>$712.05</td>
    <td>$211.11</td>
    <td>$416.87</td>
    <td>$1,364.27</td>
    <td>$712.05</td>
    <td>$211.11</td>
    <td>$416.87</td>
</tr>

and link it outside the table - <a href="#toHere">Scroll to my specified row</a>

I just did a brief search and there are other plugins out there. One is DataTables.

There are few more plugins listed in the following link that might be of help to you...

https://stackoverflow.com/questions/159025/jquery-grid-recommendations

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.