0

I have a dataTable with infinite scrolling. I want to scroll to a selected row on table refresh

$('#table1').dataTable({
    'aaData': data,
    'aoColumns': columns,
    'bInfiniteScroll': true,
    'bColumnCollapse': true,
    'sScrollY': '200px'
});

$('#btnScroll').click(function(){
     $('.dataTables_scrollBody').scrollTo($('#table1 tbody tr').eq(3), 800);
});

But it does not scroll to the row

2 Answers 2

2

You can use animate to scroll to your position

$('.dataTables_scrollBody').animate({
    scrollTop: $('#table1 tbody tr').eq(3).offset().top
}, 800)

DEMO

Sign up to request clarification or add additional context in comments.

3 Comments

Does not srcoll to the selected cell
you're using scrollTo or scrollTop?
But how can we scroll to say row 30, when the page shows only 20 rows at a time.
2

You are using the scrollTo plugin. Have you loaded it? You can write this without that plugin as follows:

var selectedRow = $('#table1 tbody tr').eq(3);
$('.dataTables_scrollBody').scrollTop(selectedRow.prop('offsetTop') - $('.dataTables_scrollBody').height()/2);

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.