Hide column with complex headers

Hide column with complex headers

poisonspoisons Posts: 25Questions: 3Answers: 0
edited July 11 in Free community support

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

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    The test case is generating this error:

    dataTables.js:1625 Uncaught
    TypeError: Cannot create property 'qty' on string 'N/A'

    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 nested columns.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

  • poisonspoisons Posts: 25Questions: 3Answers: 0

    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

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    I updated your original test case with the JSON data and the first column is hidden:
    https://live.datatables.net/mucukeho/1/edit

    Kevin

  • poisonspoisons Posts: 25Questions: 3Answers: 0

    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.

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    The only suggestions I can think of are:

    1. Make sure you aren't getting errors in the browser's console.
    2. Make sure that columns().visible() isn't called to make that column visible.
    3. Post your full Datatables init code here so we can look.

    Kevin

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    Answer ✓

    The problem might be that you have stateSave enabled. The columns.visible will hide the column but the restored state could reset the column back to visible. Comment out stateSave: true, and reload the page. Is the column now hidden? You can now uncomment stateSave: true, and the column will remain hidden.

    Kevin

  • poisonspoisons Posts: 25Questions: 3Answers: 0

    Fixed, it was the stateSave.

    Thanks so much Kevin!

Sign In or Register to comment.