2013-01-09 15 views
20

我有一個表,我使用jQuery插件的tablesorter排序。 在這裏,我想避免第一行{類=「避免排序」}待排序當選擇用於分選的任何列。 例如:避免/從使用jQuery tablesorter.js分揀過程中禁用某些特定行


 <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類= 「避免排序」 不應該進來的排序!

請幫忙!!

+0

你不能使用jQuery':不()'? –

回答

31

你有兩個選擇:

  1. 如果你使用的是原來的tablesorter,你可以得到這個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' ] 
        }); 
    
    }); 
    
+6

感謝您的回答 - 也是爲了分支和維護這個插件 - 您的版本更新更新。謝謝!!!! –

+1

頂部的東西,我有這個問題,並且cssInfoBlock修復了這個問題。謝謝! –

+0

謝謝你。你不知道我有多讚賞 – finitenessofinfinity

-3
$(function() {  
$("#myTable").tablesorter({ 
     headers: {4: {sorter: false},8: {sorter: false}} 
    }); 
}); 

這裏4,8是列數。柱0

+0

這不是問題中提出的問題。您的答案將禁用索引爲4和8的列的排序。所問的問題要忽略對某些行進行排序,而不是對列進行排序。 @ABDUL JAMAL –

0

開始在Mottie's forkstaticRow 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" 
    } 
})