【问题标题】:Uncaught TypeError: Cannot set property '_DT_CellIndex' of undefined Datatables未捕获的类型错误:无法设置未定义数据表的属性“_DT_CellIndex”
【发布时间】:2018-09-23 16:40:57
【问题描述】:

我收到此错误:

未捕获的类型错误:无法设置未定义的属性“_DT_CellIndex”

我在网上搜了一下,发现一般是th的count和td的count不匹配的时候出现的。

但我不认为这是导致问题的原因。 见下表定义:

$(document).ready(function() {
    $('#chat').DataTable({
        responsive: true,
        "bLengthChange": false,
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<link href="//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet"/>

<table class="table table-striped table-bordered" id="chat">
  <thead>
    <tr>
      <th>From</th>
      <th>To</th>
      <th>Message</th>
      <th>Time of Messgae</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>jhon</td>
      <td>rylie</td>
      <td>
        <message xmlns:cli="jabber:client" to="rylie__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="jhon_1523607791051" from="jhon__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
          <body>Hey Rylie</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 08:23:11</td>
    </tr>
    <tr>
    </tr>
    <tr>
      <td>rylie</td>
      <td>jhon</td>
      <td>
        <message xmlns:cli="jabber:client" to="jhon__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="rylie_1523607808352" from="rylie__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
          <body>Hey Jhon</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 08:23:29</td>
    </tr>
    <tr>
      <td>rylie</td>
      <td>rajanjadav</td>
      <td><i class="material-icons">play_circle_filled</i> PTT Message</td>
      <td>13-04-18 08:36:21</td>
    </tr>
    <tr>
    </tr>
    <tr>
      <td>rylie</td>
      <td>jhon</td>
      <td>
        <message xmlns:cli="jabber:client" to="jhon__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="rylie_1523608843382" from="rylie__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
          <body>what are you doing</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 08:40:43</td>
    </tr>
    <tr>
      <td>jhon</td>
      <td>rylie</td>
      <td>
        <message xmlns:cli="jabber:client" to="rylie__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="jhon_1523608972383" from="jhon__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
          <body>Nothing much</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 08:42:52</td>
    </tr>
    <tr>
    </tr>
    <tr>
      <td>jhon</td>
      <td>rylie</td>
      <td>
        <message xmlns:cli="jabber:client" to="rylie__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="jhon_1523609330813" from="jhon__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
          <body>This is for jqyeur</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 08:48:50</td>
    </tr>
    <tr>
    </tr>
    <tr>
      <td>rylie</td>
      <td>jhon</td>
      <td>
        <message xmlns:cli="jabber:client" to="jhon__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="rylie_1523609341479" from="rylie__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
          <body>okay got it msg</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 08:49:01</td>
    </tr>
    <tr>
      <td>jhon</td>
      <td>rylie</td>
      <td>
        <message xmlns:cli="jabber:client" to="rylie__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="jhon_1523611389535" from="jhon__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
          <body>Say else what are you doing</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 09:23:09</td>
    </tr>
    <tr>
    </tr>
    <tr>
      <td>rylie</td>
      <td>jhon</td>
      <td>
        <message xmlns:cli="jabber:client" to="jhon__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="rylie_1523611415081" from="rylie__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
          <body>nothing much just coding right now</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 09:23:35</td>
    </tr>
    <tr>
      <td>jhon</td>
      <td>rylie</td>
      <td>
        <message xmlns:cli="jabber:client" to="rylie__umobilityptt.7600556046@ptt.fms.bizrtc" cli:subject="TEXT MESSAGE" cli:lang="en" type="chat" id="jhon_1523611468570" from="jhon__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC">
          <body>What's ur password</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 09:24:28</td>
    </tr>
    <tr>
    </tr>
    <tr>
    </tr>
    <tr>
      <td>jhon</td>
      <td>rylie</td>
      <td><i class="material-icons">play_circle_filled</i> PTT Message</td>
      <td>13-04-18 09:27:18</td>
    </tr>
    <tr>
    </tr>
    <tr>
      <td>jhon</td>
      <td>rajanjadav</td>
      <td>
        <message xmlns:cli="jabber:client" to="rylie__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC" cli:subject="TEXT MESSAGE" cli:lang="en" type="groupchat" id="jhon_1523611651354" from="rajanjadav__umobilityptt.7600556046@conference.ptt.fms.bizrtc/jhon__umobilityptt.7600556046">
          <body>This message is sent in bizrtc group</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 09:27:31</td>
    </tr>
    <tr>
      <td>rylie</td>
      <td>rajanjadav</td>
      <td>
        <message xmlns:cli="jabber:client" to="rylie__umobilityptt.7600556046@ptt.fms.bizrtc/bizRTC" cli:subject="TEXT MESSAGE" cli:lang="en" type="groupchat" id="rylie_1523613602613" from="rajanjadav__umobilityptt.7600556046@conference.ptt.fms.bizrtc/rylie__umobilityptt.7600556046">
          <body>what happened in the meeting with Alliance</body>
          <request xmlns="urn:xmpp:receipts"></request>
        </message>
      </td>
      <td>13-04-18 10:00:03</td>
    </tr>
    </tr>
  </tbody>
</table>

对此有什么可能的解决方案?

【问题讨论】:

    标签: javascript jquery datatable datatables


    【解决方案1】:

    DataTables 期望表格中的每一行都以相同的列数填充。原因是 HTML 中的空元素。

    <tr>
    </tr>
    

    如果你删除那些空行,错误就会消失。

    【讨论】:

    • 即使我用 制作自己的空消息行,其中列跨越所有列也会导致此错误,而不仅仅是完全空 s!
    • 是的,这也会发生 - DataTables 不支持在表体中使用 colspan,仅在 thead 标头中。
    【解决方案2】:

    仅供参考:数据表也不能很好地与 colspan 配合使用。我有一个包含 3 个单元格的表格,但有一个 colspan=3 行,它们给出了相同的错误。

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签