数据表是否将1列中的所有列分组?

时间:2018-11-23 13:12:46

标签: javascript jquery html datatables

我有该表,并使用colspan创建了1行,下一行包含了我的数据。 Example in codepen

但是数据表库不起作用,并且控制台中存在一些问题:

  

未捕获的TypeError:无法设置未定义的属性'_DT_CellIndex'
      在Ha(jquery.dataTables.min.js:24)
      在O(jquery.dataTables.min.js:16)

代码:

$(document).ready(function() {
  var table = $('#example').DataTable({});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<table id="example" class="display" style="width:100%">
  <thead>
    <tr>
      <th>Name</th>
      <th>Position</th>
      <th>Office</th>
      <th>Age</th>
      <th>Start date</th>
      <th>Salary</th>
    </tr>
  </thead>
  
  <tbody>
    <tr>
      <td colspan="6">TESTTEST</td>
    </tr>
    <tr>
      <td>Tiger Nixon</td>
      <td>System Architect</td>
      <td>Edinburgh</td>
      <td>61</td>
      <td>2011/04/25</td>
      <td>$320,800</td>
    </tr>
  </tbody>
</table>

也许数据表不支持此功能,或者这是一些错误。或者,也许有人可以帮助我解决这个问题。太好了或一些小建议。

1 个答案:

答案 0 :(得分:0)

Datatables不支持Colspan。但是,您可以使用以下解决方法:

<tr>
  <td colspan="6">TESTTEST</td>
  <td style="display: none;"></td>
  <td style="display: none;"></td>
  <td style="display: none;"></td>
  <td style="display: none;"></td>
  <td style="display: none;"></td>
</tr>