SOLUTION: Auto refresh keeping scroll and row selection...
SOLUTION: Auto refresh keeping scroll and row selection...
TomNM
Posts: 8Questions: 2Answers: 0
Using datatables 1.2.2 and Scroller 1.1.0 and statesave and doing auto refreshes of my grid every 60 seconds, out of the box, the scroll position and my row selection highlight are not saved in the state. I'm not uber-efficient expert, but my solution that works is to do the following:
Declare the 2 vars I need.
$(document).ready(function() { var scrollPosition; var rowIndex; var dtable = $('#example').dataTable( {
Use the pre and post drawback functions as such:
"preDrawCallback": function( settings ) { scrollPosition = $(".dataTables_scrollBody").scrollTop(); }, "drawCallback": function( settings ) { $(".dataTables_scrollBody").scrollTop(scrollPosition); if(typeof rowIndex != 'undefined') { dtable.row(rowIndex).nodes().to$().addClass('row_selected'); } },
Record my selected row index (since I highlight those and want to refresh with my highlight):
$("#example tbody").on('click', 'tr', function() { $("#example tbody tr").removeClass('row_selected'); $(this).addClass('row_selected'); rowIndex = dtable.row(this).index(); });
Hope that helps someone.
This discussion has been closed.