create html using DataTables (do not pre-write and of the table html)

create html using DataTables (do not pre-write and of the table html)

brian15cobrian15co Posts: 1Questions: 1Answers: 0

Aplologies if this answer is straightforward, but I cannot seem to find the answer by searching.

I would like to create multiple datatables on a single page. The data is sourced from my page using ajax. I organized the json data source before fully understanding DataTables. The data looks like the following.

I am wondering if there is a way to start with no html written on the page that would contain the column names. I would like to only have to keep track of the list of column names in one spot, ideally outside of the html. This way, when new columns are added to my list I can just change the code that creates the json instead of multiple places (html for the table, javascript for the datatable, backend code for datasource, etc...).

Feel free to comment on a better way to structure my json data source. I would just like to understand if what I am thinking is feasible or a good match for DataTables.

Thanks, Brian

Answers

  • john_ljohn_l Posts: 45Questions: 0Answers: 12

    You can pass back all the details you need to define the columns in the JSON, and use that to build up skeleton tables (complete with thead/tr/th etc) before you initialize the datatables.

This discussion has been closed.