0

I have a paginated jQuery DataTable that I would like to scroll to a specific row. This row may be on another page. I am currently trying the following:

var scroller = profileTable.fnSettings().nTable.parentNode;                                              
scroller.scrollTo( $('.row_selected'), 1 );

where profileTable is a DataTable.

The row I would like to scroll to has a <tr class="row_selected">.

The Javascript error I am seeing in Chrome's Developer Tools is:

Uncaught TypeError: Object #<HTMLDivElement> has no method 'scrollTo'

I also tried

var scroller = profileTable.fnSettings().nTable.parentNode;                                              
$(scroller).scrollTo( $('.row_selected'), 1 );

with error:

Uncaught TypeError: Object [object Object]> has no method 'scrollTo'

I've tried the ScrollTo Plugin with no luck. Anybody using this plugin with jQuery 1.7.2 or higher?

Any examples of moving to a specified row in a DataTable would be appreciated.

km1
  • 2,383
  • 1
  • 22
  • 27
  • If it has no method scrollTo, you either didn't have it on the page or accidentally nuked it later on. – Mike Robinson Sep 04 '12 at 21:17
  • 1
    What is the problem with ScrollTo plugin? – Viktor S. Sep 04 '12 at 21:24
  • Also - looks like you want to scroll some scrollable div (.parentNode). Does it has a scroll bars? Or you want to put selected row at the top of window? – Viktor S. Sep 04 '12 at 21:27
  • @Fangel, not at my desk right now but it has something to do with not getting "slice" of unknown in the jquery.scrollTo-min.js file. – km1 Sep 04 '12 at 22:09
  • One problem I am seeing is that the row that has class "row_selected" is not in the DOM. It is in the HTML though. But since the DataTable is not displaying it I believe it is removed from the DOM. Guess I'll have to post another question on how to use jQuery to select an item not in the DOM. – km1 Sep 04 '12 at 22:11
  • The fnDisplayRow() is the solution. see [an answer to a similar question][1] [1]: http://stackoverflow.com/a/17961164 – dliu Nov 01 '13 at 16:16

1 Answers1

0
while(!profileTable.find($("tr.row_selected"))[0]){
    profileTable.fnPageChange( 'next' );
}
$(".dataTables_scrollBody").scrollTop( $("tr.row_selected").offset().top - $(".dataTables_scrollBody").height() );

You have to paginate to find the page which have the selected row and after that scroll to it.

George SEDRA
  • 796
  • 8
  • 11