/ / ricaricare datatable da ajax e json - javascript, php, ajax, codeigniter, datatables

ricaricare datatable da ajax e json - javascript, php, ajax, codeigniter, datatables

Sto usando tabella dati plugin e vuoi aggiornare la tabella di Ajax. Ho letto Qui per rendere il mio ritorno ajax mostra nella tabella ma non funziona. Ecco il mio codice HTML:

<button type="button" onclick="rld()">test</button>
<table id="sample_1">
<thead>
<tr>
<th> 1 </th>
<th> 2 </th>
<th> 3 </th>
</tr>
</thead>
</table>

La mia funzione java:

function rld(){
var table = $("#sample_1").DataTable( {
ajax: "<?php echo site_url("admin/test"); ?>",
deferRender: true,
columns: [
{ data: "1" },
{ data: "2" },
{ data: "3" }
],
rowId: "extn",
select: true,
dom: "Bfrtip",
buttons: [
{
text: "Reload table",
action: function () {
table.ajax.reload();
}
}
]
} );
}

Non riesco a capire quale sia il problema. non ci sono avvisi ma nella console ottengo TypeError: f non è definito e TypeError: c non è definito Che non so perché causare il mio ritorno JSON è corretto (controllato in [JSONLint] [3]). Grazie in anticipo.

risposte:

0 per risposta № 1

Grazie a tutti per l'attenzione :) Ho scoperto che non ho chiamato dove vanno i dati quando vengono restituiti come json e il nome del campo json non è uguale al nome del campo dati della colonna. Quindi apportare questa regolazione:

function reload_table(){
var table = $("#sample_1").DataTable();
table.destroy();
var table = $("#sample_1").DataTable( {
"processing": true,
"dataType": "json",
ajax: "<?php echo site_url("admin/relaod_table"); ?>",
deferRender: true,
columns: [
{ data: "user_firstname" },
{ data: "user_lastname" },
{ data: "user_status" },
{ data: "user_created_date" },
],
dom: "Bfrtip",
buttons: [
{
text: "Reload table",
action: function () {
table.ajax.reload();
}
}
]
} );
}