dynamically creation of datatables (columns and data are differnt each query ) from Json
dynamically creation of datatables (columns and data are differnt each query ) from Json
Hi, i use this code http://live.datatables.net/huyexejo/1/edit to create dynamically my datatables.
i use the function
crea_tabella_query("select* from DATABASE.TABLE;");
from a textarea i can write a new query to send to php file that extract the data in json format
but when i pass the data to the function i.e. CREA TABELLA_QUERY("ANOTHER SELECT FROM ANOTHER TABLE") i received the message
DataTables warning: table id=datatables_query - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
how can i solve?
This question has an accepted answers - jump to answer
Answers
Have you followed the steps provided in the error link?
http://datatables.net/tn/3
If you are changing the number of columns then you need to use
destroy()
before reinitializing the Datatable.Kevin
[SOLVED]
before i click the button to execute the query
i need this:
// verify if #datatables_query exist if Y delete it
if ($.fn.DataTable.isDataTable( '#datatables_query' ) ) {
var tableId = "#datatables_query";
// clear first
$('#datatables_query').DataTable().clear();
$('#datatables_query').DataTable().destroy();
//2nd empty html
$('#datatables_query' + " tbody").empty();
$('#datatables_query'+ " thead").empty();
}
then i create new $('#datatables_query') with new columns and new data
thanks
just for the ages.... :-)
$(document).on("click", "#esegui_qs", function () {
var testo_qs = document.getElementById('campo_qs').value;
console.log("text textarea : "+testo_qs);
if ($.fn.DataTable.isDataTable( '#datatables_query' ) ) {
var tableId = "#datatables_query";
// clear first
$('#datatables_query').DataTable().clear();
$('#datatables_query').DataTable().destroy();
//2nd empty html
$('#datatables_query' + " tbody").empty();
$('#datatables_query'+ " thead").empty();
}
crea_tabella_query(testo_qs);
});
you can obtain more columns that you can see in the datatables so add this option:
scrollX: true,
bye Maurizio
just for the ages.... :-)
1.
//html datatables definition in your page
hope it's useful for someone..
bye
Maurizio