首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Datatables:无法读取未定义的属性“”mData“”

Datatables:无法读取未定义的属性“”mData“”
EN

Stack Overflow用户
提问于 2014-08-19 15:18:04
回答 22查看 401.9K关注 0票数 369

我对Datatables有意见。我还检查了this link,但没有产生任何结果。我已经包含了将数据直接解析到DOM中的所有先决条件。请帮助我解决这个问题。

脚本

代码语言:javascript
复制
$(document).ready(function() {
  $('.viewCentricPage .teamCentric').dataTable({
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "bPaginate": false,
    "bFilter": true,
    "bSort": true,
    "aaSorting": [
      [1, "asc"]
    ],
    "aoColumnDefs": [{
      "bSortable": false,
      "aTargets": [0]
    }, {
      "bSortable": true,
      "aTargets": [1]
    }, {
      "bSortable": false,
      "aTargets": [2]
    }],
  });
});
EN

回答 22

Stack Overflow用户

发布于 2014-09-22 08:33:47

仅供参考dataTables需要格式正确的表。它必须包含<thead><tbody>标记,否则将抛出此错误。还要检查以确保包括标题行在内的所有行都有相同的列数。

以下代码将抛出错误(无<thead><tbody>标记)

代码语言:javascript
复制
<table id="sample-table">
    <tr>
        <th>title-1</th>
        <th>title-2</th>
    </tr>
    <tr>
        <td>data-1</td>
        <td>data-2</td>
    </tr>
</table>

下面的代码也会抛出错误(列数不相等)

代码语言:javascript
复制
<table id="sample-table">
    <thead>
        <tr>
            <th>title-1</th>
            <th>title-2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>data-1</td>
            <td>data-2</td>
            <td>data-3</td>
        </tr>
    </tbody>
</table>

有关更多信息,请访问read more here

票数 788
EN

Stack Overflow用户

发布于 2014-11-08 05:47:09

Cannot read property 'fnSetData' of undefined的常见原因是列数不匹配,如下面的错误代码所示:

代码语言:javascript
复制
<thead>                 <!-- thead required -->
    <tr>                <!-- tr required -->
        <th>Rep</th>    <!-- td instead of th will also work -->
        <th>Titel</th>
                        <!-- th missing here -->
    </tr>
</thead>
<tbody>
    <tr>
        <td>Rep</td>
        <td>Titel</td>
        <td>Missing corresponding th</td>
    </tr>
</tbody>

虽然下面的代码使用每个<th> <td>one (列数必须匹配)可以工作:

代码语言:javascript
复制
<thead>
    <tr>
        <th>Rep</th>       <!-- 1st column -->
        <th>Titel</th>     <!-- 2nd column -->
        <th>Added th</th>  <!-- 3rd column; th added here -->
    </tr>
</thead>
<tbody>
    <tr>
        <td>Rep</td>             <!-- 1st column -->
        <td>Titel</td>           <!-- 2nd column -->
        <td>th now present</td>  <!-- 3rd column -->
    </tr>
</tbody>

如果使用结构良好的头部,但没有第二行,则也会出现此错误。

对于有7列的表,以下代码不起作用,并且我们在javascript控制台中看到"Cannot read property 'mData‘of undefined“:

代码语言:javascript
复制
<thead>
    <tr>
        <th>Rep</th>
        <th>Titel</th>
        <th colspan="5">Download</th>
    </tr>
</thead>

在此过程中:

代码语言:javascript
复制
<thead>
    <tr>
        <th rowspan="2">Rep</th>
        <th rowspan="2">Titel</th>
        <th colspan="5">Download</th>
    </tr>
    <tr>
        <th>pdf</th>
        <th>nwc</th>
        <th>nwctxt</th>
        <th>mid</th>
        <th>xml</th>
    </tr>
</thead>
票数 86
EN

Stack Overflow用户

发布于 2019-05-20 14:26:03

拥有相同数量的<th><td><thead><tbody>解决了我的问题。

票数 54
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25377637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档