columnToggle initial state

columnToggle initial state

paravisparavis Posts: 37Questions: 8Answers: 1

Is there a way we can set the initial state of the columns associated with columnToggle?

Seems that when I hide the columns using DataTables options, that setting is overridden by the Buttons settings and they are shown initially.

For example, if I have a className "details" added to columns I wanted to be hidden by default, but want to allow toggling on or off, how would that be accomplished?

Thank you!

Answers

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    edited August 2016

    The initial state of the column visibility is set by columns.visible. The buttons should reflect whatever state is defined there.

    edit If that isn't working for you, please link to a test case showing the issue.

    Allan

  • paravisparavis Posts: 37Questions: 8Answers: 1

    Yes, that works. However, it brings up two new issues.

    First, we are using columnToggle with a columns value specifying a class name, so it is not a direct 1-to-1 with a button to a column. Even with these columns now initially set as hidden, their related buttons are all initially "enabled". Clicking on any of the columnToggle buttons then resets the buttons to how they should be. But the initial styling of the buttons does not reflect what is hidden and what is not hidden. This is obviously not a "game ending issue", but will confuse the users very easily. ;-)

    Second issue, and this is probably something I can deal with separately after I check it out, the row callbacks do not affect the proper cell when initially hiding columns that can be toggled visible. Maybe you can save me a bit of time - is there any reference as to how DataTables deals with hidden columns when processing the row callback functions? It has worked fine with our "always hidden" columns. But now that we are trying to hide excess data with the option of showing, it does complicate the callback a little bit.

    Any insight/suggestion would be greatly appreciated.

    Thanks again Allan. You are awesome.
    ~Laz

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    Hi Laz,

    If you are able to link to a JSFiddle, JSBin, etc showing the issue that would be useful. Otherwise I'll try to find some time to recreate a test case myself. I can see how that wouldn't be ideal.

    is there any reference as to how DataTables deals with hidden columns when processing the row callback functions?

    Again, I really need a test case to understand the code you are using, but what you probably need to do is use the API: this.api().cells( this, null ).nodes() for example if this is the rowCallback context.

    Allan

  • paravisparavis Posts: 37Questions: 8Answers: 1

    Ok - I will get something set up for you to see this. Very "unfortunate" Monday over here, we had a power supply crap out in the datacenter, and the day has been toppling over since then. ;-)

    So please give me a day or so.

    Much thanks.
    ~Laz

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    edited August 2016

    Hi Laz,

    No problem. Days like that happen! And they usually happen on a Monday or Friday...

    Allan

    edit name typo - sorry

  • paravisparavis Posts: 37Questions: 8Answers: 1

    Going to PM you regarding the two issues.

    Thanks Allan.

This discussion has been closed.