DataTables loses page with stateSave and FixedColumns

DataTables loses page with stateSave and FixedColumns

LauraDeanLauraDean Posts: 4Questions: 1Answers: 0

Hi Allan and everybody,

I can't get this to reproduce reliably on DataTables live, but there is definitely a problem when using stateSave with the FixedColumns plugin.

What I am seeing on my application is that when I select a page other than the first page and then refresh, the table data is correct but the tabIndex is set to 1.

On DataTables live, when I select a page other than the first page and then refresh, the table data is incorrectly set to the first page of data.

It does save the sort order and filtering correctly, only the page information is lost.

Here is my example:
http://live.datatables.net/zuhusew/3/edit

When I comment out the call to FixedColumns, the stateSave works correctly.

I did see that this question has been asked in the forums before, here:
https://datatables.net/forums/discussion/21880/pagination-state-not-saved-anymore-using-fixedcolumns-with-datatables-1-10

But the thread was closed with no replies...

I suspect the problem of being at line 1091 of the fixedcolumns library on cdn:
http://cdn.datatables.net/fixedcolumns/3.0.2/js/dataTables.fixedColumns.js

            var i = that.s.dt.oFeatures.bServerSide===false ?
                that.s.dt.aiDisplay[ that.s.dt._iDisplayStart+z ] : z;

Maybe if I could extend fixedcolumns so that I could set iDisplayStart to table.api().page() then it would work better?

Any advice on whether I am on the right track or how I would extend this class to pass in the extra parameter would be appreciated. Thanks!

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    This works for me (FixedColumns init outside doc.ready function).

    $(document).ready( function () {
      
      var table = $('#example').DataTable({
        stateSave: true,
        scrollCollapse: true,
        scrollY: "200px",
        scrollX: "100%"
      });
      
    } );
    new $.fn.dataTable.FixedColumns( table );
    
  • LauraDeanLauraDean Posts: 4Questions: 1Answers: 0

    Wow, thank you so much, works like a charm! I was banging my head against the wall for hours!

  • LauraDeanLauraDean Posts: 4Questions: 1Answers: 0

    Uh oh, spoke too soon... there are no fixed columns once I put this call outside the document ready function :(

  • LauraDeanLauraDean Posts: 4Questions: 1Answers: 0

    I finally got it working.

    I could find no way to set the page in the FixedColumns plugin.

    My solution a little hacky, what I had to do was save the correct page on the first fnDrawCallback, count the number of draws, and after the second draw (which is called from FixedColumns), redraw the correct page.

    Here is my code, maybe it will help someone else:
    http://live.datatables.net/fukojaco/1/edit

This discussion has been closed.