title: preserving scroll position with jquery datatables
body: <p>I'm using the DataTables plugin with the FixedColumn extension.  I’ve been trying to get a reload of the data (from an Ajax source) to happen while preserving the scroll position of the table.  If I’m in the top half of the table, it works, but below a certain point it jumps back to just past halfway scrolled.</p>
  
  <p>One approach I took was to use the JQuery Deferred pattern, as follows:</p>
  
  <pre><code>function redrawTableInPlace() {
      var docTable = $('#documentsList').dataTable();
      var scrollPos=$(".dataTables_scrollBody").scrollTop();  
      console.log("Current scroll position: " + scrollPos);
      console.log("About to redraw");
  
      $.when(docTable.fnStandingRedraw()).then($(".dataTables_scrollBody").scrollTop(scrollPos));
  }
  </code></pre>
  
  <p>That seemed to have no effect, as if the when-then structure wasn't even there.</p>
  
  <p>I’ve tried modifying DataTables to accept a callback on the draw function, but the callback doesn’t get called.  The only way I get it to work is to manually set scrollTop on the div with a setTimeout delay that is long enough for the table draw to complete, which of course is undesirable.  That code looks like this:</p>
  
  <pre><code>function redrawTableInPlace() {
      var docTable = $('#documentsList').dataTable();
      var scrollPos=$(".dataTables_scrollBody").scrollTop();  
      console.log("Current scroll position: " + scrollPos);
      console.log("About to redraw");
      docTable.fnStandingRedraw();
  
      setTimeout(function() {
          $(".dataTables_scrollBody").scrollTop(scrollPos);
          console.log("Set scroll to: " + $(".dataTables_scrollBody").scrollTop());
      }, 40000);
  
  }
  </code></pre>
  
  <p>Every suggestion I’ve found online fails, which makes me think it’s somehow related to specific DataTables plugins/functionality that we’re using.  Any thoughts?</p>