DataTables:隐藏表头时...表在移动视图中不会折叠

时间:2018-04-17 12:39:07

标签: jquery datatables

我想要隐藏表格标题...但是当这样做并让表格处于响应模式时......列不会折叠。请参阅小提琴:http://jsfiddle.net/wceu020b/

<table id="example" class="display" cellspacing="0" 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>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>
        <tr>
            <td>Garrett Winters</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>63</td>
            <td>2011/07/25</td>
            <td>$170,750</td>
        </tr>
        <tr>
            <td>Ashton Cox</td>
            <td>Junior Technical Author</td>
            <td>San Francisco</td>
            <td>66</td>
            <td>2009/01/12</td>
            <td>$86,000</td>
        </tr>
        <tr>
            <td>Cedric Kelly</td>
            <td>Senior Javascript Developer</td>
            <td>Edinburgh</td>
            <td>22</td>
            <td>2012/03/29</td>
            <td>$433,060</td>
        </tr>
    </tbody>
</table>

的CSS:

table th:nth-child(3), td:nth-child(3) {
  display: none;
}

table thead {
  display:none;
}

JS:

$(document).ready(function() {
    $('#example').DataTable( {
        responsive: true
    } );
} );

如何隐藏标题并仍使列折叠?

1 个答案:

答案 0 :(得分:4)

这与此主题非常相似:How to suppress table headers completely in jQuery DataTables?,但其他主题未提及Responsive

如果你从另一个帖子中获取@ s.krueger的答案你会得到它的工作 - 请看这个小提琴:http://jsfiddle.net/y315obr4/4/