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

我有一个 php 文件,它使用数据库中的值创建一个表。

这是打印出来的 HTML:

<table id="table" class="display dataTable no-footer">
    <thead>
        <tr class="headContainer">
            <th colspan="1"> 
                <div id="tablePerPage"></div>
            </th>
            <th colspan="1">
                <div id="tableSearch"></div>
            </th>
        </tr>
        <tr>
            <th colspan="2" class="rowHeader">
                Locations
            </th>
        </tr>
    </thead>
    <tbody id="tableContent">
        <tr class="tableRow">
            <td> 
                <a href="q=NewYork">New York</a> 
            </td>
        </tr>
    </tbody>
</table>

这里是JS代码:

$('#table').DataTable({
      autoWidth: true
      responsive: true,
      lengthChange: true,
      ordering: true
 });

 $('#tableSearch').html($('.dataTables_filter'));
 $('#tablePerPage').html($('#table_length'));

headers 是不变的,但是 body 数据是动态变化的。

如何解决这个问题?

【问题讨论】:

    标签: javascript jquery html datatable


    【解决方案1】:

    ".headContainer" 中有两个&lt;th&gt;,下一行有一个&lt;th&gt;,但有colspan="2"(相当于两个&lt;th&gt;),表体中只有一个&lt;td&gt;,它有导致表中的列和&lt;td&gt; 数据“不匹配”。

    如果你添加另一个&lt;td&gt;:

    <tbody id="tableContent">
        <tr class="tableRow">
            <td>
                <a href="q=NewYork">New York</a>
            </td>
            <td>
                <a href="q=Chicago">Chicago</a>
            </td>
        </tr>
    </tbody>
    

    DataTables 应该很高兴。

    【讨论】:

      猜你喜欢
      • 2018-09-23
      • 1970-01-01
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      相关资源
      最近更新 更多