Hide empty columns

Hide empty columns

viegaviega Posts: 2Questions: 0Answers: 0
edited December 2011 in General
Hi there,

I am pretty new to Datatables, so sorry in advance if this has been asked already - but the search function does not return a result I can work with.

I am generating a table using a server side script. The script returns a pretty big table. Only some of the columns are filled and they differ from result to result. Is there a way to hide empty columns (while the header is filled) after generating the table?

Dennis

Replies

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    The simple answer is no - there isn't way build in way of doing this. Having said that, there is no reason why the API can't be used to do this - all you could need to do is know if a column is empty or not (http://datatables.net/plug-ins/api#fnFilterOnReturn might help with that) and set the column visibility to hidden or not: http://datatables.net/api#fnSetColumnVis

    Allan
  • viegaviega Posts: 2Questions: 0Answers: 0
    Thanks for the hint!
    I now just check if a column is empty using the serverside script and hid them with fnSetColumnVis. That works for me :-)

    Dennis
  • okeletokelet Posts: 10Questions: 3Answers: 0
    Could you paste an example how have you done this? Looping over all columns and then hide those empty...

    Regards.
  • sergeserge Posts: 1Questions: 0Answers: 0
    Allan, I'm a bit confused, your link points to fnFilterOnReturn (although clicking it actually takes you to fnGetHiddenNodes), what does dealing with the return key have to do with seeing which columns have no data?
This discussion has been closed.