使用jQuery tablesorter.js避免/禁用排序过程中的某些特定行

时间:2013-01-09 08:31:42

标签: jquery tablesorter

我有一个表,我使用jquery插件tablesorter进行排序。 这里我想避免在选择任何列进行排序时对第一行{class =“avoid-sort”}进行排序。 例如:


       <thead>
        <tr>
            <th class="header">#</th>
            <th class="header">Purchase Date</th>
            <th class="header">Course Name</th>
            <th class="header">Amount(in $)</th>
            <th class="header">User Name</th>
            <th class="header">Share</th>
            <th class="header">Net Revenue [$236.41]</th>
        </tr>
      </thead>
  <tbody>

       <tr class="avoid-sort">
            <th colspan="7">Total Revenue</th>
            <td>236.41</td>
        </tr>

        <tr>
                <td>1</td>
                <td>January 3rd, 2013</td>
                <td>Tackle Certification</td>
                <td>50</td>
                <td>Khushi Jha</td>
                <td>35</td>
                <td>33.69</td>
        </tr>
      <tr>
                <td>2</td>
                <td>January 3rd, 2013</td>
                <td>Flag Certification</td>
                <td>100</td> 
                <td>Pay</td>
                <td>70</td>
                 <td>67.67</td>
      </tr>
                            <tr>
                <td>3</td>
                <td>January 3rd, 2013</td>
                <td>Tackle Certification</td>
                <td>50</td>
                <!--                    <td>-->
                    <!--</td>-->
                <td>Pay</td>
                <td>35</td>
                 <td>33.69</td>

   </tr>

  


tr class =“avoid-sort”不应该排序!

请帮助!!

3 个答案:

答案 0 :(得分:34)

您有两种选择:

  1. 如果您使用的是原始的chartorter,则可以使用此static row widget来“锁定”该行。

  2. 如果您使用的是fork of tablesorter,则可以添加一个不可排序的tbody,如下所示(demo):

    <table>
    <thead>
      ...
    </thead>
    
    <!-- rows within this tbody are ignored -->
    <tbody class="avoid-sort">
      <tr>
        <th colspan="7">Total Revenue</th>
        <td>236.41</td>
      </tr>
    </tbody>
    
    <tbody>
      <!-- sortable rows -->
      <tr>
        ...
      </tr>
    </tbody>
    </table>
    

    然后像这样初始化表:

    $(function() { 
    
      $("table").tablesorter({ 
        theme : 'blue', 
        cssInfoBlock : "avoid-sort", 
        widgets: [ 'zebra' ] 
      }); 
    
    });
    

答案 1 :(得分:0)

Mottie's fork staticRow plugin is now built-in

<script src="/js/tablesorter/jquery.tablesorter.min.js"></script>
<script src="/js/tablesorter/widgets/widget-staticRow.min.js"></script>
<!-- … -->
<tr class="static">…</tr>
$("table").tablesorter({
    widgets: ['staticRow']
})

或者,您可以设置自定义类名:

<tr class="tablesorter-static">…</tr>
$("table").tablesorter({
    widgets: ['staticRow'],
    widgetOptions: {
        // Note it expects a CSS selector, not a raw class name
        staticRow_class: ".tablesorter-static"
    }
})

答案 2 :(得分:-3)

<com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="XXXXX">
    </com.google.android.gms.ads.AdView>

这里有4,8列号。列以0开头