Dynamically grab column name from data file
Dynamically grab column name from data file
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
This discussion has been closed.
Replies
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.