How do I go-to / scroll to row without using scroller plug-in?
How do I go-to / scroll to row without using scroller plug-in?
Is it possible to scroll to a row when vertical scrolling is enabled but NOT the scroller plug-in? I know of the fnScrollToRow method with the scroller plug-in but the scroller plug-in locks up on mobile devices when you scroll fast so I am not using that in my my application. I have also tried the fnDisplayRow API plug-in function but that only works with pages? Any ideas?
This discussion has been closed.
Replies
[code]
function goToRow(iRowIndex, oTable) {
var iScrollingDivSize, iScrollingDivHeight, iTotalNumOfRows, iRowHeigth, iNewPosition;
/* Get total height of scrolling div, height of DIV (set in sScrollY), and total number of rows */
iScrollingDivSize = jQuery('#DataTablesDIV .dataTables_scrollBody')[0].scrollHeight;
iScrollingDivHeight = jQuery('#DataTablesDIV .dataTables_scrollBody')[0].offsetHeight;
iTotalNumOfRows = oTable.fnSettings().fnRecordsTotal();
/* Calculate height of each row */
iRowHeigth = iScrollingDivSize / iTotalNumOfRows;
/* Calculate pixels down in scrolling DIV to center row in scrolling DIV */
iNewPosition = (iRowHeigth * iRowIndex) - (iScrollingDivHeight / 2);
/* Bounds check */
if (iNewPosition > iScrollingDivSize) {iNewPosition = iScrollingDivSize; }
if (iNewPosition < 0) {iNewPosition = 0; }
/* Goto row */
jQuery('#DataTablesDIV .dataTables_scrollBody').scrollTop(iNewPosition);
}
[/code]
Is the scrolling DIV height set in the "sScrollY" initialization setting present somewhere in oTable.fnSettings()? I am pulling a parameter I found in the jQuery object right now but rather get it from the datatable settings.
For example: http://live.datatables.net/akepus/edit#javascript,html
> Is the scrolling DIV height set in the "sScrollY" initialization setting present somewhere in oTable.fnSettings()?
Yes - its in oScroll.sY : http://datatables.net/docs/DataTables/1.9.3/DataTable.models.oSettings.oScroll.html#sY
Allan