what's wrong with my dataTable ajax reload
what's wrong with my dataTable ajax reload
is there anything wrong with my ajax.reload after ajax (sweetalert) success callback?
var table = $('#dataTable').dataTable({
"language": {
"lengthMenu": "Munculkan MENU Data",
"search": "Cari Berdasarkan Nama:",
"info": "Menghasilkan Data Sebanyak PAGE Dari PAGES Tabel"
}
});
success: function (response) {
swal('Deleted!', response.message, response.status);
table.ajax.reload(null, false);
},
Been trying with table.api()... , shows me: 'DataTables warning: table id=dataTable blabla' and table.ajax.reload(); still shows me 'TypeError: table.ajax is undefined' in the Console
This question has an accepted answers - jump to answer
Answers
I'm assuming you are using a recent version of Datatables?
If so then this:
Should look like this:
Notice the capital
d
for DataTable. See the first FAQ here for details:https://datatables.net/faqs/index#Most-common-FAQs
I believe for
ajax.reload()
to work you need to define the ajax using the Datatable'sajax
. If you define outside of DT then it doesn't have the URL defined to execute theajax.reload()
.If you want to use ajax outside of the Datatables init options then you can use
clear()
followed byrows.add()
to populate the table with the new data.Kevin
Thank you for your response. I'm using the ajax outside of DT, cause it contains swal for confirmation. However, can the swal be inside the DT? Anyway, gonna give a shot for that method. Thank you again
If you aren't using the
ajax
optionajax.reload()
isn't going to help you. You'd need to useclear()
to clear the table and thenrows.add()
to add new rows that you've got from your external Ajax.Allan