i should reload the data in my datatable after using a function to delete item i put the function in different file of the datatable : this is my delete function:
我应该在使用函数删除项目后重新加载数据表中的数据我将函数放在数据表的不同文件中:这是我的删除函数:
function removeFunction(table,id) {
var txt= $('.titleSup').text();
var txt2= $('.textSup').text();
swal({
title:"Delete",
text: txt,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes !",
cancelButtonText: "No, cancel",
closeOnConfirm: false, closeOnCancel: false
}, function(isConfirm){
if (isConfirm) {
$.ajax({
url: "ajax/delete.php?for="+table+"&id="+id,
success : function(data){
if(data == 'ok'){
swal({
title:"Delete",
text: txt2,
type: "success",
confirmButtonColor: "#AEDEF4",
confirmButtonText: "Ok",
closeOnConfirm: true,
}, function(isConfirm){
//reload here
});
}else{
swal("Error, try again", "", "error");
}
}
}); // end ajax call
} else {
swal("Cancel", "", "error");
}
});
}
and this is the file of my datatable :
这是我的数据表的文件:
var TableData = function () {
//function to initiate DataTable
//DataTable is a highly flexible tool, based upon the foundations of progressive enhancement,
//which will add advanced interaction controls to any HTML table
//For more information, please visit https://datatables.net/
var runDataTable = function () {
var oTable = $('#sample_1').dataTable({
"sAjaxSource": 'ajax/get_companys.php',
"aoColumns": [
{ "mData": "register_no" },
{ "mData": "name" },
{ "mData": "email" },
{ "mData": "phone" },
{ "mData": "fax" },
{ "mData": "nbr_customer" },
{ "mData": "nbr_user" },
{ "mData": "created" }
],
"aoColumnDefs": [{
"aTargets": [0]
}],
"oLanguage": {
"sLengthMenu": "Show _MENU_ Rows",
"sSearch": "",
"oPaginate": {
"sPrevious": "",
"sNext": ""
}
},
"aaSorting": [
[2, 'desc']
],
"aLengthMenu": [
[5, 10, 15, 20, -1],
[5, 10, 15, 20, "All"] // change per page values here
],
// set the initial value
"iDisplayLength": 10,
});
};
return {
//main function to initiate template pages
init: function () {
runDataTable();
}
};
}();
how can i access to the datatable element and relaoad his data source in the success function of the ajax call in the RemoveFunction, Thanks.
如何在RemoveFunction中的ajax调用的成功函数中访问datatable元素并重新加载他的数据源,谢谢。
2 个解决方案
#1
0
you just have to use $("#sample_1").dataTable().draw();
你只需要使用$(“#sample_1”)。dataTable()。draw();
#2
0
Simple, use $("#sample_1").DataTable().ajax.reload();
notice that it's DataTable with capital D to access the API or you can also use $("#sample_1").DataTable().draw();
简单,使用$(“#sample_1”)。DataTable()。ajax.reload();注意它是带有大写D的DataTable来访问API,或者你也可以使用$(“#sample_1”)。DataTable()。draw();
#1
0
you just have to use $("#sample_1").dataTable().draw();
你只需要使用$(“#sample_1”)。dataTable()。draw();
#2
0
Simple, use $("#sample_1").DataTable().ajax.reload();
notice that it's DataTable with capital D to access the API or you can also use $("#sample_1").DataTable().draw();
简单,使用$(“#sample_1”)。DataTable()。ajax.reload();注意它是带有大写D的DataTable来访问API,或者你也可以使用$(“#sample_1”)。DataTable()。draw();