Use Case Question: JSON for ALL instantiation needs
Use Case Question: JSON for ALL instantiation needs
KJustice
Posts: 3Questions: 1Answers: 0
Hi - I'd like to know if this is possible as I have a specific use case for it.
I know I can use JSON for the data, but is there a means of using JSON (a separate JSON file) to configure the datatable itself including the columns such that the only thing on the html page would be a div that datatables uses?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I build my tables fairly similarly to how you're describing, you'll need to build out the table using JavaScript, PHP, or whatever Web language you desire to build out the DataTable from the JSON that describes it. Given that the options for building a DataTable is in a format that is JSON valid, it should be as easy as
Where
inJSON
is the JSON describing the table you want to build.My example would support this, but note that you will need at least some JavaScript for the table to be formed (my line above) plus you'll need all the JavaScript and CSS files for DataTables itself, you won't be able to run a DataTable without JavaScript on the page.
@JLegault - This is exactly what I was thinking. I'm new to datatables - do you have an example of what your inJSON data would look like?
(And I guess I didn't mean that I wouldn't include js and css files...that was short sighted on my part.)
Thanks a bunch!!!
Actually I just needed to do some more digging once I got on the right thread (Thanks again @JLegault. For anyone else trying this, these will help.
https://github.com/martinberlin/datatables-dynamic-columns
https://stackoverflow.com/questions/28140671/datatables-with-dynamic-columns
https://datatables.net/forums/discussion/33886/dynamic-columns-from-ajax-data-source
https://embed.plnkr.co/plunk/2BzDEu
https://jsfiddle.net/craigvt/oLrgjrvd/
https://blog.pheonixsolutions.com/dynamic-column-header-result-ajax-call-jquery-datatable/
Awesome glad I could be of help!