When adding a row to a vertically scrolling table, can I keep the state of the scrollbar?
When adding a row to a vertically scrolling table, can I keep the state of the scrollbar?
ivarni
Posts: 2Questions: 0Answers: 0
I am using "sScrollY": 300 in a table
(So basically http://datatables.net/release-datatables/examples/basic_init/scroll_y.html)
and I am adding data to it clientside using fnAddData. If I have scrolled down a few rows in the table so that the top row is not visible and add a row with fnAddData it scrolls to the top.
If, on that page, you were to scroll down in the table a bit and then run
$('#example').dataTable().fnAddData(['zot','baz','bar','foo','SPROING'])
You'll see the table scroll to the top.
Is there a way to prevent this? Any help would be appreciated.
Cheers,
Ivar
(So basically http://datatables.net/release-datatables/examples/basic_init/scroll_y.html)
and I am adding data to it clientside using fnAddData. If I have scrolled down a few rows in the table so that the top row is not visible and add a row with fnAddData it scrolls to the top.
If, on that page, you were to scroll down in the table a bit and then run
$('#example').dataTable().fnAddData(['zot','baz','bar','foo','SPROING'])
You'll see the table scroll to the top.
Is there a way to prevent this? Any help would be appreciated.
Cheers,
Ivar
This discussion has been closed.
Replies
Regards,
Kim
$('#example').dataTable().fnAddData(['zot','baz','bar','foo','SPROING'], false)
Before _fnDraw gets called (as a result of adding, removing or updating a row)
[code]
globals.scrollPos = $('.dataTables_scrollBody').scrollTop();
[/code]
Then, when initializing the table add
[code]
"fnDrawCallback": function(oSettings) {
$('.dataTables_scrollBody').scrollTop(globals.scrollPos);
},
[/code]
Not an optimal solution, but gets the work done.
[code]
$('#example').dataTable().fnAddData(['zot','baz','bar','foo','SPROING'], false);
$('#example').dataTable().fnDraw(false);
[/code]