不能重新初始化数据表 - 动态数据的数据表 [英] Cannot reinitialise DataTable - dynamic data for datatable

查看:953
本文介绍了不能重新初始化数据表 - 动态数据的数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表显示所有员工。 这是工作的罚款为所有员工的document.ready 。 我有一个包含员工的类型,如project_manager'和一个选择标记; team_leader,以及对员工的类型,我调用一个函数的变化 get_employees(EMP_TYPE),并通过所选择的员工类型。

I have a datatable showing all employees. It is working fine for all employees on document.ready. I have a select tag containing the type of employees like 'project_manager' & 'team_leader' , and on change of employee type I am calling a function get_employees(emp_type) and passing the selected employee type.

这是越来越希望在Ajax响应适当的数据,但投掷警告

It is getting desired and proper data in ajax response, but throwing warning

DataTables warning: table id=example - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

我试图消灭它,但没有运气。

I tried to destroy it, but no luck.

也试过

$('#example').dataTable().fnClearTable();
$('#example').dataTable().fnDestroy();

据清表,并呈现出新追加的数据,但列名,每次添加新的排序图像。

it is clearing table and showing newly appended data, but adding new sort images with column name every time.

下面是我的code段。

Here is my code snippet.

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

在此先感谢。

Thanks in advance.

推荐答案

在数据表(1.10.4)的当前版本,你可以简单地添加破坏:真正的的配置,以确保任何表已经present之前被重新初始化删除。

In the current version of DataTables (1.10.4) you can simply add destroy:true to the configuration to make sure any table already present is removed before being re-initialised.

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

这篇关于不能重新初始化数据表 - 动态数据的数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆