SaveState only if column visibility has been change

SaveState only if column visibility has been change

jardojardo Posts: 2Questions: 1Answers: 0

Hello everyone,
I'm using dataTables in pair with column visibility plugin and I would like to save state of column visibility into database per each user per table. I have in plan use StateSave functionality, but I ran into a issue with stateSaveCallback which is called on every draw basically (search, order ...).
My question is, is there a way I can limit this stateSave trigger, only to column visibility change? Because saving state into DB after each filter or order is not acceptable.
I tried use StateSaveParams and delete search and order, but since those are not in settings dictionary anymore, both trigger stateSaveCallback.
Last shot is to do it all in column-visibility.dt event callback, and handle saving state to DB here.
Thank you for your response in advance.
http://live.datatables.net/govukewo/1/edit

Answers

  • allanallan Posts: 56,203Questions: 1Answers: 8,902 Site admin

    My question is, is there a way I can limit this stateSave trigger, only to column visibility change?

    If you wanted to limit the state saving in such a way you'd need to have a variable that would keep the last column visibility state - in your state save callback check if the columns have changed, and if so, then run the save and update the variable with the last column visibility check.

    Allan

  • jardojardo Posts: 2Questions: 1Answers: 0

    Thank you for quick answer.
    This also came to my mind, but I wanted to avoid unnecessary execution, since in this case I would have to check if variable columns has changed every time user perform search (on every keyup event) change order etc.
    That is why I hoped for some "flag" that tells me, what event causes state to be saved. Even If no, I will probably end up with either saving in column-visibility event callback or do It the way you described.
    If you have any other idea to help me out, I would be more grateful.
    Have a nice day.

Sign In or Register to comment.