How to scroll to the new added row?

How to scroll to the new added row?

mkadusalemkadusale Posts: 10Questions: 0Answers: 0
edited February 2012 in General
Good Day!
I am new to DataTables and following this example http://datatables.net/blog/Inline_editing
When I add lots of rows already a scroll will appear and every time I add a new row it will add at the bottom which is what I like but
the problem is it will not be shown. Any inputs would be appreciated.

Replies

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Are you using the built in scrolling? If so, if the new row is always going to add to the bottom of the table you could just scroll to the bottom of the div.dataTables_scrollBody element.

    A more robust solution is to get the position of the newly added row in the table (in pixel terms) - this you would do by letting the table draw and then using the jQuery position method to get the position and then scroll to that point.

    Allan
  • mkadusalemkadusale Posts: 10Questions: 0Answers: 0
    I am sorry but I am not familiar with jQuery position method.
    Can you please give an example on how to get the scroll position and then after refreshing the table set the scroll postion using jQuery postion method?

    Thanks in Advance!
  • elgarchelgarch Posts: 13Questions: 0Answers: 0
    Add this line :

    $('html,body').animate({scrollTop: $("#id_of_your_table_or_wathever").offset().top},300);

    Hope it will help u ;)
This discussion has been closed.