Table state and column visibility

Table state and column visibility

squigsquig Posts: 14Questions: 0Answers: 0
edited July 2009 in General
Hi Allan,

I really appreciate your work on DataTables. Thanks for that :)

Today I was able to refill my column filters using bSaveState option. But I'm missing information about the visibility of the columns. Would it possible to store this also into the cookie?

With kind regards,

squig

Replies

  • allanallan Posts: 62,211Questions: 1Answers: 10,205 Site admin
    Hi squig,

    Are you using the API function for changing column visibility during run time? If so then you are quite correct - this information is not currently saved by the information in the cookie. I've added this onto my to do list, and it should be in the next release.

    Regards,
    Allan
  • squigsquig Posts: 14Questions: 0Answers: 0
    Hi Allan,

    you're right, I'm using the API functions to show and hide the columns. Happy to hear that you'll put it into the next release. Thank you.


    With kind regards,

    squig
  • squigsquig Posts: 14Questions: 0Answers: 0
    Hi Allan,

    just tried DataTables 1.5 beta 10, column visibility is saved and restored correctly, thank you :)

    When restoring you're overwritting the initial values for visibility. Is there are way to preserve them? Or should I just send them in an extra array to the client?


    With kind regards,

    squig
  • allanallan Posts: 62,211Questions: 1Answers: 10,205 Site admin
    HI squig,

    This was the one thing I was uncertain about with how I implemented the restore state for the columns. However, I couldn't think of what benefit not overwriting them would be - although having said that, I can see now that if you are passing an object into DataTables as the initialiser then the values will be overwritten. Is this what is happening in your case here?

    There was another method I tried where it would only apply the visibility after everything was initialised. I'm wondering if a better way of doing it might be something like this, and then use the set visibility function internally at the end of initialisation to restore the table state. It might also address some of the problems that bAutoWidth can cause...

    Allan
  • squigsquig Posts: 14Questions: 0Answers: 0
    Hi Allan,

    when the table is first shown some columns are hidden, which depends on configuration applied on the server side. After DataTables drops in I use the bVisible property of aoColumns to save the initial state of visibilty on the client side.
    The user can use a dialog to switch visibility of a column but has also a button to reset visibility back to inital state.
    So I want to keep current state of visibility when the user switches pages but also the inital view state.

    The first time I can access aoColumns is after everything is initialised. So it makes no difference for me how the state from the cookie is transfered into DataTables, the initial state is lost. Or do I miss something?

    I think I can fix this if I would provide an additional JavaScript variable containing the initial visibility which is written into the delivered page by the server. So I wouldn't longer rely on aoColumns to get initial view state.

    squig
  • allanallan Posts: 62,211Questions: 1Answers: 10,205 Site admin
    HI squig,

    You are quite right in that the information from the state saving cookie will overwrite your aoColumns passed data. If you want this information as well, then yes, I would recommend that you output it from the server into a Javascript array / object, and use it from there. That way you can combine the logic form DataTables and your own server-side script into whatever it is that you need. Unfortunately, this kind of thing is necessary as DataTables must try to take into account many different deployment cases.

    Regards,
    Allan
  • squigsquig Posts: 14Questions: 0Answers: 0
    Hi Allan,

    it works perfectly for me as it is now, thanks again for your help and quick introduction of state support for column visibility :)


    With kind regards,

    squig
This discussion has been closed.