StateSave and column visibility

StateSave and column visibility

svashtarsvashtar Posts: 8Questions: 3Answers: 0
edited February 2017 in General

Hi,

i have a datatable where i define on TH a class "not-visible" if the column should be hidden.
This visibility class is set based on some conditions.

I am also using statesave, so users keep the search etc.

The problem is, when the state is saved and "not-visible" is changed, these columns behave strangely.

What would be a proper way to handle this scenario?

Answers

  • allanallan Posts: 61,609Questions: 1Answers: 10,088 Site admin

    When state saving is enabled, the state that is loaded will be the one that "wins". State saving will override the initialisation settings - that's the whole point of state saving :smile:.

    So to allow your class to work, you'd need to clear the saved state.

    Allan

  • svashtarsvashtar Posts: 8Questions: 3Answers: 0

    OK, i understand that, it is logical :)

    But, I bet i am not the only one with such a case. And for this kind of situations, is there really no way like saying: ok, save everything, but ignore columns (with some kind of identifier, in my case css class.).

    My case is that i have users who have their roles. And based on permissions set to a role, a column for mass edit (check boxes) is hidden or visible.

    This is pretty much the whole story :)
    And it is a big decision/tradeoff between usability of datatable save state and being able to set some security based elements inside the table.

    Thx for the answer :)

  • allanallan Posts: 61,609Questions: 1Answers: 10,088 Site admin

    is there really no way like saying: ok, save everything, but ignore columns

    Yes, you can have it ignore columns. The stateSaveParams callback can be used for this. You can have it delete the columns parameter and everything will be saved except the column information.

    Allan

  • itajackassitajackass Posts: 121Questions: 37Answers: 3

    Can you post an example?

    For example (with StateSave: true and target column = 1 with visible: false and class="col_to_hide") using:

    "stateSaveParams": function (settings, data) {
    //
    }

  • allanallan Posts: 61,609Questions: 1Answers: 10,088 Site admin

    If you want to not state save column visibility you could remove the visible parameter from the columns array of objects in the state object:

    stateSaveParams: function ( settings, data ) {
      for ( var i=0, ien=data.columns.length ; i<ien ; i++ ) {
        delete data.columns[i].visible;
      }
    }
    

    Allan

This discussion has been closed.