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?

ivarniivarni Posts: 2Questions: 0Answers: 0
edited October 2012 in DataTables 1.9
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

Replies

  • KimAMKimAM Posts: 2Questions: 0Answers: 0
    Was wondering about the same thing myself. Anyone that can help?

    Regards,
    Kim
  • DaveGYNWADaveGYNWA Posts: 10Questions: 0Answers: 0
    Not tried it myself, but what is the effect of this?

    $('#example').dataTable().fnAddData(['zot','baz','bar','foo','SPROING'], false)
  • KimAMKimAM Posts: 2Questions: 0Answers: 0
    The table will not redraw, so the new entry will not appear in the table. Not the solution I am looking for. Thanks anyways!
  • ivarniivarni Posts: 2Questions: 0Answers: 0
    Workaround using JQuery:

    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.
  • swarogDarkswarogDark Posts: 1Questions: 0Answers: 0
    Hello. If question still actual you can use this trick:
    [code]
    $('#example').dataTable().fnAddData(['zot','baz','bar','foo','SPROING'], false);
    $('#example').dataTable().fnDraw(false);
    [/code]
This discussion has been closed.