setting scrollTop does not work

setting scrollTop does not work

redwoodswederedwoodswede Posts: 1Questions: 0Answers: 0
edited April 2014 in General
I'm using DataTables with an Ajax datasource to display a list of documents. In my application, users can assign topics to an entry in the table. When a topic is assigned, we want to redraw the table from the datasource (which is now updated with the topic), and retain the scroll position of the table.

Everything I've seen says to set scrollTop() to the desired value. Following an example on the forum (http://datatables.net/forums/discussion/8074/scroll-datatable-to-bottom/p1), I've modified the fnStandingRedraw function as follows:

[code]
$.fn.dataTableExt.oApi.fnStandingRedraw = function(oSettings) {
if(oSettings.oFeatures.bServerSide === false){
var before = oSettings._iDisplayStart;

oSettings.oApi._fnReDraw(oSettings);

// iDisplayStart has been reset to zero - so lets change it back
oSettings._iDisplayStart = before;
oSettings.oApi._fnCalculateEnd(oSettings);
}

var scrollPos=$(".dataTables_scrollBody").scrollTop();

console.log("Current scroll position: " + scrollPos);

// draw the 'current' page
oSettings.oApi._fnDraw(oSettings);

setTimeout(function() {
console.log("Setting scroll to: " + scrollPos);
$(".dataTables_scrollBody").scrollTop(scrollPos);
console.log("Set scroll to: " + $(".dataTables_scrollBody").scrollTop());
}, 0);
};
[/code]
(The example from the forum uses fnReloadAjax, but my table refresh calls fnStandingRedraw.)

This works for some values returned by scrollTop(), specifically anything under about half of the maximum scrollTop value for the table. This maximum value appears to be 5623. Anything below that, and the table scrolling position is retained. Any value above that, and it jumps back to the point specified by 5623.

I should note that I originally used fnStandingRedraw without setting scrollTop and observed similar behavior; the current modification is based on examples found on the forums. Also, I'm using FixedColumns in my table. Are there any known conflicts between extras/plugins and either the fnStandingRedraw or fnReloadAjax functions?

I apologize for not having an example, it's an internal company application so I'm not able to post our code.
This discussion has been closed.