gpt4 book ai didi

jquery - 无法重新初始化数据表 - 数据表的动态数据

转载 作者:行者123 更新时间:2023-12-03 21:38:17 25 4
gpt4 key购买 nike

我有一个显示所有员工的数据表。它对 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();

它正在清除表格并显示新附加的数据,但每次都会添加带有列名称的新排序图像。

这是我的代码片段。

$(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,
});
}
});
}

提前致谢。

最佳答案

在当前版本的 DataTables (1.10.4) 中,您只需将 destroy:true 添加到配置中,以确保在重新初始化之前删除任何已存在的表。

$('#example').dataTable({
destroy: true,
aaData: response.data
});

关于jquery - 无法重新初始化数据表 - 数据表的动态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24545792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com