无法读取null的属性'nTable'

时间:2015-06-12 11:21:04

标签: php jquery datatables jquery-datatables

我最近用数据表设置了我的第一次尝试。

当我测试我的网站时,我会在控制台中收到一些错误....任何人都知道如何解决它们?

Uncaught TypeError: Cannot read property 'nTable' of null
_fnCallbackFire @ jquery.dataTables.js:5242
_fnLog @ jquery.dataTables.js:5070
(anonymous function) @ jquery.dataTables.js:6111
m.extend.each @ jquery.js:2
m.fn.m.each @ jquery.js:2
DataTable @ jquery.dataTables.js:6092
$.fn.DataTable @ jquery.dataTables.js:14775
(anonymous function) @ datatable.php:134
m.Callbacks.j @ jquery.js:2
m.Callbacks.k.fireWith @ jquery.js:2
m.extend.ready @ jquery.js:2
J @ jquery.js:2

脚本将加载到标题部分。通过包括header.php当我直接进入页面时,它不会改变任何东西。

加载以下脚本:

<script type="text/javascript" charset="utf-8" src="/assets/js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="/assets/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="/assets/js/dataTables.tableTools.js"></script>
<script type="text/javascript" charset="utf-8" src="/assets/js/dataTables.editor.js"></script>

版本:

  • jQuery v1.11.3
  • DataTables 1.10.7
  • TableTools 2.2.4
  • dataTables.editor 1.4.2

您可以在此处找到我的代码:https://ghostbin.com/paste/46x7v

1 个答案:

答案 0 :(得分:0)

您在DataTables初始化代码中有一个拼写错误,其中colums应该是columns

$('#adminlist').DataTable( {
    dom: "Tfrtip",
    ajax: "assets/php/table.admins.php",
    columns: [
        {data: "id" },
        {data: "name" },
        {data: "joindate" },
        {data: "section" },
        {data: "tutor" },
        {data: "lesson1" },
        {data: "lesson2" },
        {data: "lesson3" },
        {data: "versus" },
        {data: "insults" }
    ],
    tableTools: {
        sRowSelected: "os",
        aButtons: [
            { sExtends: "editor_create", editor: editor },
            { sExtends: "editor_edit",   editor: editor },
            { sExtends: "editor_remove", editor: editor }
        ]
    }
});

此外,您的代码<section class="container"未关闭,应为<section class="container">