Ajax sourced data
Ajax sourced data
gmstephane
Posts: 4Questions: 3Answers: 0
Hello
how can i read from ajax sourced data with unknown header colonne. I mean the data i get from database can varie en terms of number of column. so i need the columns in the table to be dynamically created from javascript.
Answers
See this FAQ. Here is a simple example:
https://live.datatables.net/huyexejo/1925/edit
It derives the column names from the object keys in the row data. You could return a specific object with the column header names. Use
columns.title
to define the header names.Kevin
Hello kthorngren
Thank you for your quick reply. it put me on the right track.
But one more, in the example https://live.datatables.net/huyexejo/1925/edit is there a particular format of the json data to be used in the javascript?
here is a sample of the code
The Ajax docs provide details of what Datatables expects for the row data. The example I provided simply uses the first object in the array to build the column headers from the object keys.
If this doesn't do what you want you can return the header names in a different object along side the
data
object. Since this is something you are adding and Datatables doesn't use it you can return any format that works for your solution.Kevin