[Filtering] Hide an empty column
[Filtering] Hide an empty column
            
                            
                                  in DataTables             
        Hi everyone,
I've got on my company's website a DataTable with a search bar for each column (thanks to the plugin).
That being said, I would like to hide the empty columns.
If, for example, a search gives me projects which don't have any comments on. In this case, the "comments" field would disappear.
The code is fragmented in so many files I couldn't send it here, just ask if you need more infos.
Thx in advance,
Zirion.
This discussion has been closed.
            
Answers
You could do that in
initComplete. Iterate through the columns data withcolumn().data()andeach()(see the example on that page), and if the data is all empty, callcolumn().visible(),Colin
There's something I don't get : how are you supposed to know if
valueis empty ? It does not seem to be an array, and it makes things more difficult to analyse.Here is a screenshot of the result of

console.log(value + " " + index)We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin