tablesorter with two header rows

旧巷老猫 提交于 2019-11-30 03:05:38

问题


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>

回答1:


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/



来源:https://stackoverflow.com/questions/16823951/tablesorter-with-two-header-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!