简体   繁体   English

jQuery DataTable多行标头

[英]jQuery DataTable multi rows header

I used jQuery DataTable to show some data. 我使用jQuery DataTable来显示一些数据。

Here is my code . 这是我的代码

I tried to add collapse/expand using bootstrap collapse functionality. 我尝试使用引导折叠功能添加折叠/展开。

So I made two rows. 所以我做了两行。

But if you see console it throws an javascript error so code below it not running. 但是,如果您看到控制台,它将引发一个javascript错误,因此其下面的代码无法运行。

How can I fix this? 我怎样才能解决这个问题?

Here is html code: 这是html代码:

 <table id="taskTable"> <thead class="bg-light text-capitalize"> <tr> <th>Subject</th> <th>Name</th> <th>Duration</th> <th>User</th> </tr> <tr style="display:none;"> <th></th> </tr> </thead> <tbody> <tr data-toggle="collapse" data-target="#demo1"> <td>Subject1</td> <td>Name1</td> <td>Duration1</td> <td>User1</td> </tr> <tr id="demo1"> <td>aaa</td> </tr> <tr data-toggle="collapse" data-target="#demo2"> <td>Subject2</td> <td>Name2</td> <td>Duration2</td> <td>User2</td> </tr> <tr id="demo2"> <td>aaa</td> </tr> </tbody> </table> 

Not feeling good using this approach: Because of search, the sort, etc will break the concept of <tr> as header and it's next <tr> as content. 使用这种方法感觉不太好:由于搜索的原因,排序等将破坏<tr>作为标头,而下一个<tr>作为内容的概念。

Maybe you can achieve the same thing using a different approach, like you can have child rows like here . 也许您可以使用不同的方法来实现相同的目的,例如您可以拥有类似于此处的子行。 But you can also fix the above problem as below: 但是您也可以按以下方式解决上述问题:

JS Fiddle JS小提琴

HTML HTML

<table id="taskTable">
  <thead class="bg-light text-capitalize">
    <tr>
      <th>Subject</th>
      <th>Name</th>
      <th>Duration</th>
      <th>User</th>
    </tr>
    <tr style="display:none;">
      <th colspan="4"></th>
    </tr>
  </thead>
  <tbody>
    <tr data-toggle="collapse" data-target="#demo1">
      <td>Subject1</td>
      <td>Name1</td>
      <td>Duration1</td>
      <td>User1</td>
    </tr>
    <tr id="demo1">
      <td colspan="4">aaa</td>
      <td style="display: none;"></td>
      <td style="display: none;"></td>
      <td style="display: none;"></td>
    </tr>
    <tr data-toggle="collapse" data-target="#demo2">
      <td>Subject2</td>
      <td>Name2</td>
      <td>Duration2</td>
      <td>User2</td>
    </tr>
    <tr id="demo2">
      <td colspan="4">aa2</td>
      <td style="display: none;"></td>
      <td style="display: none;"></td>
      <td style="display: none;"></td>
    </tr>
  </tbody>
</table>

JS JS

$("#taskTable").dataTable({
  "ordering": false
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM