簡體   English   中英

如何禁用jQuery.tablesorter中的列排序?

[英]How to disable sorting on column in jQuery.tablesorter?

我試圖找到一種方法來禁用對列的排序。 我使用jQuery插件tablesorter 並且默認情況下,如果您單擊標題單元格,它將對列數據進行排序,但是如果我不需要對四列表中的一列或兩列使用排序,該怎么辦。

提前致謝。

您必須在初始化時傳遞適當的參數,例如:

{ ...
   headers: { 0: { sorter: false} }
}

有關更多信息,請參見以下手冊:

http://tablesorter.com/docs/

您也可以使用html數據屬性:

<th data-sorter="false">...</th>

或者您可以使用一個類:

<th class="sorter-false">...</th>

就像是:

$('#selector').tablesorter({headers: {0: { sorter: false}}});

此處明確列出了這一點: http : //tablesorter.com/docs/example-options-headers.html

 $(document).ready(function() { $("#myTable").tablesorter({ // pass the headers argument and assing a object headers: { // assign the secound column (we start counting zero) 1: { // disable it by setting the property sorter to false sorter: false }, // assign the third column (we start counting zero) 2: { // disable it by setting the property sorter to false sorter: false } } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.21.2/js/jquery.tablesorter.min.js"></script> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.21.2/css/theme.blue.min.css' type='text/css' /> <table id='myTable' cellspacing="1" class="tablesorter-blue"> <thead>> <tr> <th>first name</th> <th>last name</th> <th>age</th> <th>total</th> <th>discount</th> <th>date</th> </tr> </thead> <tbody> <tr> <td>peter</td> <td>parker</td> <td>28</td> <td>$9.99</td> <td>20%</td> <td>jul 6, 2006 8:14 am</td> </tr> <tr> <td>john</td> <td>hood</td> <td>33</td> <td>$19.99</td> <td>25%</td> <td>dec 10, 2002 5:14 am</td> </tr> <tr> <td>clark</td> <td>kent</td> <td>18</td> <td>$15.89</td> <td>44%</td> <td>jan 12, 2003 11:14 am</td> </tr> <tr> <td>bruce</td> <td>almighty</td> <td>45</td> <td>$153.19</td> <td>44%</td> <td>jan 18, 2001 9:12 am</td> </tr> <tr> <td>bruce</td> <td>evans</td> <td>22</td> <td>$13.19</td> <td>11%</td> <td>jan 18, 2007 9:12 am</td> </tr> </tbody> </table> 

對於單列xpapad是正確的

對於多列禁用排序

標頭:{0:{分類器:錯誤},1:{分類器:錯誤},2:{分類器:錯誤}}

http://tablesorter.com/docs/#Configuration

tablesorter v2.18.1中 ,您現在可以通過標頭內元素的類名來定位列; 請注意,該范圍在名字列中具有目標的類名稱。

的HTML

 <table class="tablesorter">
   <thead>
    <tr>
     <th><span class="first-name">First Name</span></th>
     ...

JS

  $("table").tablesorter({
     headers: {
       '.first-name' : {
       sorter: false
     }
   }
 });

tablesorter v2.0.5和更早的版本中,僅元數據和標頭選項方法可用。

2.3+版本中 ,可以使用以下任何一種方法(優先級相同)來禁用列:

  • jQuery數據data-sorter="false"

     <table class="tablesorter"> <thead> <tr> <th data-sorter="false">Age</th> .... 
  • 元數據class="{ sorter: false }" (這需要元數據插件)

  • 標頭選項headers : { 0 : { sorter: false } }

     $("table").tablesorter({ headers : { 0 : { sorter: false } }) 
  • 標頭類名稱class="sorter-false"

     <table class="tablesorter"> <thead> <tr> <th class="sorter-false">Discount</th> .... 
  • 直接使用jQuery數據禁用列,但是在表初始化之前執行。

     $("table thead th:eq(5)").data("sorter", false); $("table").tablesorter( 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM