Hide column with complex headers
Hide column with complex headers
poisons
Posts: 25Questions: 3Answers: 0
Is it possible to hide a column with complex header?
You can see in this test case
https://live.datatables.net/idinat/869/edit
I simplified the case, inreality it is an ajax return, you will see some conditional code.
I try to hide column 0, I tried both in column specification and in column definition, but it seems it doesn't work
This question has an accepted answers - jump to answer
Answers
The test case is generating this error:
You have
data: "detailPcs.2.qty"
defined but are not supplying nested data via ajax or Javascript. The error is causing the script to stop and Datatables is not initialized. Removing the nestedcolumns.data
definitions allows Datatables to complete initialization and the first column is hidden.https://live.datatables.net/nocutefi/1/edit
You could update your test case to use Javascript data, like this example, by grabbing one or more rows from the Ajax response.
Kevin
I cannot edit anymore
I've setup an example with ajax, where I wrote the Json Object in another file,
https://live.datatables.net/redagino/1/edit
following the example here
https://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read#latest
I don't know if I setup the example properly, but it is not working on my project too
I updated your original test case with the JSON data and the first column is hidden:
https://live.datatables.net/mucukeho/1/edit
Kevin
Thanks for your prompt rely and for your edit, it helps a lot.
Is there anything I can do to debug it deeper? Because that json is what I receive from the ajax call, and both the js and the table structure are the same as on the live environment, still the column is visible.
The only suggestions I can think of are:
columns().visible()
isn't called to make that column visible.Kevin
The problem might be that you have
stateSave
enabled. Thecolumns.visible
will hide the column but the restored state could reset the column back to visible. Comment outstateSave: true,
and reload the page. Is the column now hidden? You can now uncommentstateSave: true,
and the column will remain hidden.Kevin
Fixed, it was the stateSave.
Thanks so much Kevin!