Creating a Datatable with a string
Creating a Datatable with a string
![prox108](https://datatables.net/forums/uploads/userpics/269/nVX6DJ114ZNE1.png)
Hello, I created a table inside a string.
"<table><thead></thead><tbody><tr>cabezera 1<th>cabezera 2</th></tr><tr><td>data1</td><td>data1</td></tr></body></table>"
Do you know how can I create the table with this string?
This question has accepted answers - jump to:
Answers
Your table syntax is incorrect:
Looks like the first tor you want as the header so it should be moved into the
thead
. Also the first cell (cabezera 1
) is missing theth
tags. It should look like this:The Datatable can be initialized with
new DataTable('table');
. Running example:https://live.datatables.net/benigafi/1/edit
Kevin
What I am trying to do is initialitaze the Datable with this string, I am not trying to create it directly inside a html file but create inside a js file using the regular definition of Datatable. Do you know what propiete has datable to define all the strcuture of the datable?
You can use jQuery or Javascript methods to insert the table into the document then initialize the Datatable. There isn't a configuration option to have Datatables insert the string for you.
Kevin
It sad, but thanks!
Its a single line of jQuery:
Our if you don't want to use jQuery, set the
innerHTML
property of an element - also a single line of code.That is not something DataTables should provide.
Allan
I know, I alredy used some similar code
$('#thistorico').html(d);