How do I modify fnDisplayRow to animate scrolling to the effected row?
How do I modify fnDisplayRow to animate scrolling to the effected row?
robertbrower
Posts: 158Questions: 1Answers: 0
I'm trying to modify the fnDisplayRow plugin so that the row being displayed is scrolled to the top of the scrollbody. But I can't get it to work.
Since I do not want to return if the display all is selected I commented that out. It is the bit of code after this.oApi._fnDraw(oSettings); which has got me stumped.
[code]
$.fn.dataTableExt.oApi.fnDisplayRow = function (oSettings, nRow) {
// Account for the "display" all case - row is already displayed
// if (oSettings._iDisplayLength == -1) {
// return;
// }
// Find the node in the table
var iPos = -1;
for (var i = 0, iLen = oSettings.aiDisplay.length; i < iLen; i++) {
if (oSettings.aoData[oSettings.aiDisplay[i]].nTr == nRow) {
iPos = i;
break;
}
}
// Alter the start point of the paging display
if (iPos >= 0) {
oSettings._iDisplayStart = (Math.floor(i / oSettings._iDisplayLength)) * oSettings._iDisplayLength;
this.oApi._fnCalculateEnd(oSettings);
}
this.oApi._fnDraw(oSettings);
var $row = $(nRow);
var $scrollBody = $(oSettings.nTableWrapper).find(".dataTables_scrollBody");
var $table = $scrollBody.children().first();
$scrollBody.animate({
scrollTop: $row.position().top
});
};
[/code]
When scrolling to higher index rows, the scroll bar just disappears. Any tips are appreciated greatly. Thank you.
Robert
Since I do not want to return if the display all is selected I commented that out. It is the bit of code after this.oApi._fnDraw(oSettings); which has got me stumped.
[code]
$.fn.dataTableExt.oApi.fnDisplayRow = function (oSettings, nRow) {
// Account for the "display" all case - row is already displayed
// if (oSettings._iDisplayLength == -1) {
// return;
// }
// Find the node in the table
var iPos = -1;
for (var i = 0, iLen = oSettings.aiDisplay.length; i < iLen; i++) {
if (oSettings.aoData[oSettings.aiDisplay[i]].nTr == nRow) {
iPos = i;
break;
}
}
// Alter the start point of the paging display
if (iPos >= 0) {
oSettings._iDisplayStart = (Math.floor(i / oSettings._iDisplayLength)) * oSettings._iDisplayLength;
this.oApi._fnCalculateEnd(oSettings);
}
this.oApi._fnDraw(oSettings);
var $row = $(nRow);
var $scrollBody = $(oSettings.nTableWrapper).find(".dataTables_scrollBody");
var $table = $scrollBody.children().first();
$scrollBody.animate({
scrollTop: $row.position().top
});
};
[/code]
When scrolling to higher index rows, the scroll bar just disappears. Any tips are appreciated greatly. Thank you.
Robert
This discussion has been closed.
Replies
http://balupton.github.io/jquery-scrollto/
The row is scrolled to but the top of the table seems to get cut off which makes the scrollbar disappear...
Are you using Scroller? What's the configuration of your table? I've heard of the scrollTo plug-in being used successfully with DataTables before.
Allan
Now I use the unmodified fnDisplayRow to go to the correct page.
Then I use this plugin: http://flesler.blogspot.de/2007/10/jqueryscrollto.html to scroll to the row.
I'm not sure what's up with the other scrollTo plugin, but this one is good.
Works nicely.
Robert