Scroller: determine if a row is visible in the viewport
Scroller: determine if a row is visible in the viewport
I've enabled browser back-button support so hitting on back button will return a user to the previously selected row. However as long as that row is visible I do not want to use oScroller.fnScrollToRow, only when the row is not visible.
I have the row index of the row. How can i determine if that row is currently visible in the viewport or not?
I have the row index of the row. How can i determine if that row is currently visible in the viewport or not?
This discussion has been closed.
Replies
Allan
yeah that would be nice. I've now implemented following custom workaround which more or less works. I guess adding parameter to the function could make it more generally usable instead of my hardcoded stuff.
[code]
function isRowVisible(rowIndex){
var oSettings = myTable.fnSettings();
var scrollBody = $('#myTable_wrapper .dataTables_scrollBody');
var scrollTop = $(scrollBody[0]).scrollTop();
var rowToPixels = oSettings.oScroller.fnRowToPixels(rowIndex);
var scrollY = parseInt(oSettings.oScroll.sY);
// for edge cases, as far as I can tell header height is 20 px
// if only 1 line high and is included in scrollY
scrollY = scrollY - 21;
if((scrollTop + scrollY) < rowToPixels
||scrollTop > rowToPixels) {
return false;
} else {
return true;
}
}
[/code]
Allan
EDIT:
the solution is this:
[code]
var rowIndexes = myTable.fnFindCellRowIndexes(id, "id" );
var rowIndex = rowIndexes[0];
rowIndex = oSettings.aiDisplay.indexOf(rowIndex); //aiDisplay takes sorting and filtering into account
[/code]