2

I want to hide the table header ... but when doing so and having the table in responsive mode ... the columns are not collapsing. Please see Fiddle: 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
    } );
} );

How can I hide the header and still make the columns collapse?

Philipp M
  • 3,306
  • 5
  • 36
  • 90

1 Answers1

4

This is very similar to this thread: How to suppress table headers completely in jQuery DataTables?, though that other thread doesn't mention Responsive.

If you take @s.krueger's answer from that other thread you'll get it working - see this fiddle here: http://jsfiddle.net/y315obr4/4/

colin0117
  • 1,448
  • 1
  • 11
  • 15