Hide column using column render inside the columnDefs
Hide column using column render inside the columnDefs
BlamelessVictim
Posts: 3Questions: 1Answers: 0
I'm trying to hide the column if it had a certain value init what am doing wrong?
this is https://jsfiddle.net/afk147zs/1/
im trying to hide column age if it contain age 41
This question has an accepted answers - jump to answer
Answers
columns.render
is not the place for this. UseinitComplete
and get thecolumn().data()
for the column. Then check the array for the value(s) you want to hide the column. Usecolumn().visible()
to hide the column. Like this:https://jsfiddle.net/zf4La3kb/
Kevin
it is thanks a bunch Kevin, I also want to ask what if I want to hide the column if all the data inside the column is the same but if there is a single data that is different the column will be shown,
for example,
https://jsfiddle.net/7brqguw0/
I fill the age2 column with a bunch of zero but at the end, I put some value that is not zero but the data wasn't shown
Thank you for your help
Use
toArray()
to convert thecolumn().data()
to a standard array. Then use Javascript techniques to evaluate the array. This SO thread has some techniques to evaluate if an array contains all the same values. See this example:https://jsfiddle.net/davmcxze/
Kevin
Thank you Kevin, it works