DataTables未捕获TypeError:无法设置未定义的属性“0”

时间:2022-08-24 14:52:19

I have a repeater and wrap it all with DataTables library. Here is the following js function.

我有一个转发器,并用DataTables库包装它。这是以下js函数。

function createDataTable() {
    $(document).ready(function() {
        $('#tblMessages').dataTable({
            "sPaginationType": "full_numbers",
            "sDom": '<"clreol"lf><"scrollable_datatable"rt><"clreol"ip>',
            "bPaginate": true,
            "bLengthChange": false,
            "bFilter": true,
            "bInfo": false,
            "bAutoWidth": false,
            "bAutoHeight": false,
            "bSort": false,
            "bStateSave": true,
            "iCookieDuration": 60*60*24
        });
    });
}

I got no pagination at all just scroll bar on the right side of the repeater. And I got this on console:

我完全没有分页只是转发器右侧的滚动条。我在控制台上得到了这个:

Uncaught TypeError: Cannot set property '0' of undefined jquery.dataTables.min.js:366
Y                                                        jquery.dataTables.min.js:366
(anonymous function)                                     jquery.dataTables.min.js:454
jQuery.extend.each                                       jquery.min.js:21
jQuery.fn.jQuery.each                                    jquery.min.js:12
i.fn.dataTable                                           jquery.dataTables.min.js:434
(anonymous function)                                     Message.aspx:156
jQuery.fn.extend.ready                                   jquery.min.js:26
createDataTable                                          Message.aspx:152

What's wrong? And what should I do?

怎么了?我该怎么办?

1 个解决方案

#1


6  

Check your table structure:

检查你的表格结构:

  • Number of columns (th) in thead section must equal number of columns (td) in tbody section. See manual for proper HTML structure.

    thead部分中的列数(th)必须等于tbody部分中的列数(td)。有关正确的HTML结构,请参见手册

  • If you're using colspan or rowspan attributes for th elements in thead section, make sure that each column has one unique th element. See this example for more info and demonstration.

    如果您对thead部分中的元素使用colspan或rowspan属性,请确保每列都有一个唯一的元素。有关详细信息和演示,请参阅此示例。

#1


6  

Check your table structure:

检查你的表格结构:

  • Number of columns (th) in thead section must equal number of columns (td) in tbody section. See manual for proper HTML structure.

    thead部分中的列数(th)必须等于tbody部分中的列数(td)。有关正确的HTML结构,请参见手册

  • If you're using colspan or rowspan attributes for th elements in thead section, make sure that each column has one unique th element. See this example for more info and demonstration.

    如果您对thead部分中的元素使用colspan或rowspan属性,请确保每列都有一个唯一的元素。有关详细信息和演示,请参阅此示例。