Dynamically grab column name from data file

Dynamically grab column name from data file

intnamintnam Posts: 2Questions: 0Answers: 0
edited August 2011 in General
Hi all, is there a way to dynamically display the name of columns? For example, can I put "aoColumns" to a JSON data file, and don't define anything in .dataTables() and area? In this way, different JSON data file will cause the datatable to look differently. I did some tests, but without any luck, or this is pretty impossible? Thanks

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited August 2011
    I don't think there's a datatables way of doing that, but you could write code to do it yourself.

    if the number of columns are consistent, you could define a minimal skeleton of the TABLE element with a THEAD element with the right number of columns.

    if the number is not consistent, you could create a TABLE dynamically with Javascript or JQuery before initializing DataTables on the TABLE.

    You can use the object form of aaData to specify column names (at the data level. you'll still need to copy them over to your TABLE or specify them in the DataTables initializer), or you could use your own format.
  • intnamintnam Posts: 2Questions: 0Answers: 0
    Thanks fbas, I will try to archieve it from another way then.. Many thanks
This discussion has been closed.