Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tablesorter with two header rows

I am using the tablesorter jquery plugin and my table has two rows in the header. Is there any way to enable sorting on my table? it should be able to be sortable by the second header row the first header row is just there to group related data by a date. If this is not possible using this plugin maybe someone has a suggestion for a workaround?

Here is an example of my table markup

<table>
  <thead>
    <tr>
      <th colspan="3">January</th>
      <th colspan="3">February</th>
      <th colspan="3">March</th>
    </tr>
    <tr>
      <!-- January -->
      <th>Metric 1</th>
      <th>Metric 2</th>
      <th>Metric 3</th>
      <!-- February -->
      <th>Metric 1</th>
      <th>Metric 2</th>
      <th>Metric 3</th>
      <!-- March -->
      <th>Metric 1</th>
      <th>Metric 2</th>
      <th>Metric 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <!-- January -->
      <td>Value 1</td>
      <td>Value 2</td>
      <td>Value 3</td>
      <!-- February -->
      <td>Value 1</td>
      <td>Value 2</td>
      <td>Value 3</td>
      <!-- March -->
      <td>Value 1</td>
      <td>Value 2</td>
      <td>Value 3</td>
    </tr>
    <tr>...</tr>
    <tr>...</tr>
    <!-- etc -->
  </tbody>
<table>
like image 543
Devin Crossman Avatar asked May 29 '13 21:05

Devin Crossman


1 Answers

All you had to do was try ;)

http://jsfiddle.net/Mottie/4mVfu/402/

If you want the top row disabled, then add a sorter-false class to those header cells:

<tr>
  <th class="sorter-false" colspan="3">January</th>
  <th class="sorter-false" colspan="3">February</th>
  <th class="sorter-false" colspan="3">March</th>
</tr>

http://jsfiddle.net/Mottie/4mVfu/403/

like image 199
Mottie Avatar answered Sep 27 '22 21:09

Mottie