jQuery表格排序組件-tablesorter

來源:互聯網
上載者:User

一、引入檔案

<script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.tablesorter.js"></script> <!-- 引入以下樣式則表頭出現排序表徵圖,同時引入圖片  --><link href="css/style.css" rel="stylesheet" type="text/css" >
效果



二、標準的HTML表格,必須包括thead和tbody標籤

<table id="myTable" class="tablesorter">      <thead>         <tr>             <th>Name</th>             <th>Sex</th>             <th>Address</th>         </tr>      </thead>      <tbody>         <tr>             <td>zhangsan</td>             <td>boy</td>             <td>beijing</td>             </tr>         <tr>             <td>lisi</td>             <td>girl</td>             <td>shanghai</td>         </tr>         <tr>     ...略        </tr>     </tbody> </table> 

三、設定table可排序

$(document).ready(function(){      //第一列不進行排序(索引從0開始)     $.tablesorter.defaults.headers = {0: {sorter: false}};     $(".tablesorter").tablesorter(); });

官方文檔:http://tablesorter.com/docs/


補充說明:

在使用過程遇到的一個問題,我的表格式資料是通過ajax擷取的,首頁進行排序的時候沒問題

當進行下一頁排序的時候,會把上頁的資料也重新顯示出來,解決這個問題可以在你ajax擷取資料之後

觸發"update"事件,代碼如下:

$(".tablesorter").trigger("update");

以上問題著實頭疼了很久,剛開始用的官網上的Pager plugin,發現這個不太合適。

又網上查資料 整理以下代碼:

$(".tablesorter tbody tr").addClass("delete");  $(".tablesorter tbody tr.delete").remove();  $("table tbody").append(html);$(".tablesorter").trigger("appendCache");$(".tablesorter").trigger("update");$(".tablesorter").trigger("sorton",[[[2,1],[0,0]]]); 

於是都用上了,久經測試 發現只有 $(".tablesorter").trigger("update");這一句能解決問題

其他的不知道是什麼東東。

所需檔案:http://download.csdn.net/detail/itmyhome/7389871

style.css及圖片在themes\blue路徑下。




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.