2013年2月21日 星期四

HTML 表格排序:使用 tablesorter

想要讓網頁表格依某一欄排序,不想在伺服器端動手腳,看 jQuery 能不能在瀏覽器端達成。網路搜尋 jQuery 表格排序,得到的答案就是要加用 tablesorter plugin,那就來用看看。

使用 tablesorter 很簡單,前提是表格必須要有 <thead></thead> 及 <tbody></tbody> 讓 tablesorter 知道表頭跟表身在哪裡。除此之外只需要文件載入後呼叫 tablesorter(),並可作預設排序欄位等設定。tablesorter 會自動偵測大部分的資料格式,例如數字、日期、IP 位址等。

網頁 <head> 區範例如下:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.tablesorter.js"></script>
<script>
$(document).ready(function() {
  $("table").tablesorter({ // 呼叫 tablesorter
    sortList: [[0,0]] // 預設排序:第一欄,由小而大
  });
});
</script>

沒有留言:

張貼留言

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...