What happens to additional header cells when a column is hidden by default

What happens to additional header cells when a column is hidden by default

CharleyCharley Posts: 66Questions: 17Answers: 0

It's kind of hard to explain what I'm looking for, but here's what I've got going on.

I've got an function that adds a column based search to each column (based on some attributes, and classes that I've defined).

step 1: I add the row and cells before the table is created,
step 2: initialize the table
step 3 I have an option to add a select filter (which grabs all of the unique values of that column), so I don't actually add the select box or input box until after table initialized

this works fine, as long as all of the table columns are visible by default.

BUT... if I make something hidden by default, the the cells that I'm looking for in step 3 aren't there.

so I need to either
1. Figure out where those cells have gone so that I can tweak them even if they're hidden
or
2. move all of this to whatever method fires when the column draws for the first time

Answers

  • colincolin Posts: 15,236Questions: 1Answers: 2,598

    Hi @Charley ,

    The problem is probably because in step 3 you're adding the select filter to the column header (or footer perhaps), when it isn't there as it's invisible.

    The solution is to add the select filter when the column becomes visible. You could either do this in the code as part of the visibility action, or trigger on the event column-visibility.

    Hope that helps,

    Cheers,

    Colin

  • CharleyCharley Posts: 66Questions: 17Answers: 0

    it's not just invisible on step 3; I can't find it anywhere in the DOM. Changes to it do get persisted though, so it's got to be stored somewhere.

    Adding it after it become visible was my option 2; I'd really rather do that set up upfront.

  • colincolin Posts: 15,236Questions: 1Answers: 2,598

    Hi @Charley ,

    Yep, when a column is made invisible, it's removed from the DOM and only exists in the DataTables cache. I'm happy to take a look if you can link to a test case demonstrating the issue.

    Cheers,

    Colin

This discussion has been closed.