Dynamically Add DataTable Column Headings Data Rows
Dynamically Add DataTable Column Headings Data Rows
Does anyone have an example of dynamically adding column headings to a Datatable and rows of data using the API?
All of the examples here, depend on the and elements being in the and and being in the . I would like to dynamically create the 's in the and . Does the API support this?
All of the examples here, depend on the and elements being in the and and being in the . I would like to dynamically create the 's in the and . Does the API support this?
This discussion has been closed.
Replies
As for an exmaple:
Your server side response will be a json object of the table columns such as:
[code]
["Col 1", "Col 2", "Col 3", "Col 4", "Col 5" ]
[/code]
You Javascript code would look like:
[code]
$.getJSON('/path_to_your_server_side_script.php'),function(data)
{
//Create the table
tablehtml = '';
$.each(data, function()
{
tablehtml += ''+this+'';
}
tablehtml += '';
$('body').append(tablehtml);
//Make it a DataTables
$('#MyTable').dataTable();
}
[/code]