【发布时间】:2014-08-24 02:39:07
【问题描述】:
我有一个显示所有员工的数据表。
document.ready 上的所有员工都可以正常工作。
我有一个选择标签,其中包含 'project_manager' & 'team_leader' 之类的员工类型,并且在更改员工类型时,我正在调用函数 get_employees(emp_type) 并传递所选的员工类型。
在 ajax 响应中获得了所需且正确的数据,但会发出警告
DataTables warning: table id=example - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
我试图摧毁它,但没有成功。
也试过
$('#example').dataTable().fnClearTable();
$('#example').dataTable().fnDestroy();
清表并显示新添加的数据,但每次都添加带有列名的新排序图像。
这是我的代码 sn-p。
$(document).ready(function() {
get_employees('all');
});
function get_employees(emp_type)
{
$.ajax({
url: '../ajax_request.php',
type: "POST",
data: {
action: "admin_get_all_employees",
type: emp_type
},
success: function(response) {
var response = jQuery.parseJSON(response);
// $('#example').destroy(); tried this but haven’t worked
$('#example').dataTable({
"aaData": response.data,
});
}
});
}
提前致谢。
【问题讨论】:
标签: jquery ajax dynamic datatable destroy