JQuery.datatable无刷新多种初始化表格的使用方式。
ajax.reload( callback, resetPaging )
里面有二个参数:
callback :当服务器返回数据并重绘完毕时执行此回调方法,回调方法返回的是服务器返回的数据
resetPaging: 重置(默认或者设置为true)或者保持分页信息(设置为false)
var table = $('#example').DataTable( {
ajax: "data.json"
});
做数据处理的时候,执行某个方法,会重新reload()
$.ajax({
type: "post",
url: "edit",
data: {id: data.id},
async: true,// 默认:true为异步请求
dataType: "json",
success: function (data) {
if (data.type == 'success') {
tableData.ajax.reload();//会重载所有接口数据,返回到第一页
} else {
alert(data.msg);
}
}
});
重新加载表数据(分页留存);
$.ajax({
type: "post",
url: "edit",
data: {id: data.id},
async: true,// 默认:true为异步请求
dataType: "json",
success: function (data) {
if (data.type == 'success') {
tableData.ajax.reload(null, false);//如果在方法里传二个参数,重新加载表数据(分页页码保留);
} else {
alert(data.msg);
}
}
});