Intialization of table with aaData inside of a function
Intialization of table with aaData inside of a function
I'm stuck with this.
I have an ajax call that returns me a json, in the succes method i have a call to initializate a table with that json parameters, the table fills and everything is ok, but if the event is fired again, then i have a problem.
here is the code:
$('#fileAdd').change(function() {
debugger;
var fileAdd = document.getElementById("fileAdd").files[0].name;
$.ajax({
url : 'ajax/getAumento.action',
data : { "fileAdd" : fileAdd},
type : 'GET',
dataType : 'json',
success : function(json) {
debugger;
makeTables(json);
},
error : function(json) {
alert('error');
}
});
});
function makeTables(data){
// t.destroy();
debugger;
if ( $.fn.dataTable.isDataTable( '#aumentoTable' ) ) {
//t.fnReloadAjax();
} else {
t = $('#aumentoTable').DataTable( {
"aaData": data.itemsAumento,
"jQueryUI": true,
"dom": '<"search"f><"toolbar">tlp',
"buttons": true,
aoColumns: [ {"data" : "nombre",
"width" : "18%"},
{"data" : "costo"
}],
});
}
if the table doesn't exists then i initilizate the table, the problem is when the table is already initialize and i have to reload it, with the parameter (Data) with aaData, anybody knows how can i do this? or if this posible.
pd: t.fnReloadAjax(); give an error cause of T is undefined
Regards