stateSave and multiple tabs

stateSave and multiple tabs

Anja_RAnja_R Posts: 3Questions: 1Answers: 0

I'm having a table with 3 tabs. I would like to save the sort order for each tab.

I have added
stateSave: true
to my DataTable.

Now I do save the sort order, but it is "reused" for each tab, which somehow overrules the visibility of my columns, so columns which are supposed only to be visible in one tab, now are visible in all tabs.

How do I save the state for each tab individually?
and if this isn't possible, can I set options to stateSave, so it only saves sort order and not filter?

Sorry for not providing a test case, but I hope it's a fairly simply issue of (knowing and) setting the right options, if not I will try to provide more info.

Kind regards
Anja

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,176Questions: 1Answers: 2,589

    Hi @Anja_R ,

    The tabs aren't that straightforward, I'm afraid, as each tab is likely to be a different table - see this example here. Depending upon how you implemented it, would depend upon the solution to the problem.

    That said, you can use the stateSaveParams to modify the data being saved, or you could fiddle with stateLoadParams and remove options you don't want.

    Cheers,

    Colin

  • Anja_RAnja_R Posts: 3Questions: 1Answers: 0

    I ended up using the following, where tabType is a uniq identifier for my tabs

    stateSave: true,
    
    stateSaveCallback: function(settings,data) {
          localStorage.setItem( 'DataTables_' + globalVars.tabType, JSON.stringify(data) );
        },
    
    stateLoadCallback: function(settings) {
          return JSON.parse( localStorage.getItem( 'DataTables_' + globalVars.tabType ) )
        }, 
    
  • colincolin Posts: 15,176Questions: 1Answers: 2,589
    Answer ✓

    Excellent, glad all working :)

This discussion has been closed.