tablesorter 的使用
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Email</th>
<th>Due</th>
<th>Web Site</th>
</tr>
</thead>
<tbody>
<tr>
<td>Smith</td>
<td>John</td>
<td>jsmith@gmail.com</td>
<td>$50.00</td>
<td>http://www.jsmith.com</td>
</tr>
<tr>
<td>Bach</td>
<td>Frank</td>
<td>fbach@yahoo.com</td>
<td>$50.00</td>
<td>http://www.frank.com</td>
</tr>
<tr>
<td>Doe</td>
<td>Jason</td>
<td>jdoe@hotmail.com</td>
<td>$100.00</td>
<td>http://www.jdoe.com</td>
</tr>
<tr>
<td>Conway</td>
<td>Tim</td>
<td>tconway@earthlink.net</td>
<td>$50.00</td>
<td>http://www.timconway.com</td>
</tr>
</tbody>
</table>
1. 需要引入的资源
<script type="text/javascript" src="/path/to/jquery-latest.js"></script>
<script type="text/javascript" src="/path/to/jquery.tablesorter.js"></script>
2.使用demo
 $(document).ready(function() 
     // demo1 : 初始化,使表格可排序
     $("#myTable").tablesorter(); 
     // demo1 : 默认第一列,第二列按升序排序
     $("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} ); 
     // demo3 : 手动触发排序
     $("myTable").trigger("sorton",[[0,0],[2,0]]);
     // demo4 : 禁止列排序
     $("table").tablesorter({
         headers: {
             // 列序号默认从0开始
             1: {
                 // 第二列不可排序
                 sorter: false
             },
             2: {
                 sorter: false
             }
         } ,
         // 启用调试模式
         debug: true
     }); 
     // demo5 : 强制默认排序列
     $("table").tablesorter({
         // set forced sort on the fourth column and i decending order.
         sortForce: [[0,0]]
     }); 
     // demo6 : 改变多条件排序使用的辅助键,默认shift
     $("table").tablesorter({
         sortMultiSortKey: 'altKey' ,
         textExtraction: function(node) {
             // extract data from markup and return it
             return node.childNodes[0].childNodes[0].innerHTML;
         }
     }); 
     // demo7 : 给table 添加元数据也可达到排序的目的,metadata插件会自动获取类属性
     <table cellspacing="1" class="tablesorter {sortlist: [[0,0],[4,0]]}"> 
     // demo8 : 也可以在th的class中指定排序
     <tr>
         <th class="{sorter: false}">first name</th>
         <th>last name</th>
         <th>age</th>
         <th>total</th>
         <!-- 指定数据解析类型 -->
         <th class="{sorter: 'text'}">first name</th>
         <th class="{sorter: false}">discount</th>
         <th>date</th>
     </tr> 
     // demo9 : 指定sort相关事件
     $("table").bind("sortStart",function() {
         $("#overlay").show();
     }).bind("sortEnd",function() {
         $("#overlay").hide();
     }); 
     // demo10 : 动态添加数据
     $("table tbody").append(html);
     // 通知插件需要更新
     $("table").trigger("update");
     var sorting = [[2,1],[0,0]];
     // 触发排序事件
     $("table").trigger("sorton",[sorting]); 
     // demo11 : 修改默认参数
     $.tablesorter.defaults.sortList = [[0,0]]; 
     // demo12 : 自定义排序类型
     $.tablesorter.addParser({
         // set a unique id
         id: 'grades',
         is: function(s) {
             // return false so this parser is not auto detected
             return false;
         },
         format: function(s) {
             // format your data for normalization
             return s.toLowerCase().replace(/good/,2).replace(/medium/,1).replace(/bad/,0);
         },
         // set type, either numeric or text
         type: 'numeric'
     }); 
     $(function() {
         $("table").tablesorter({
             headers: {
                 6: {
                     sorter:'grades'
                 }
             }
         });
     }); 
     // demo14 : 自定义组件
     $.tablesorter.addWidget({
         // give the widget a id
         id: "repeatHeaders",
         // format is called when the on init and when a sorting has finished
         format: function(table) {
             // cache and collect all TH headers
             if(!this.headers) {
                 var h = this.headers = [];
                 $("thead th",table).each(function() {
                     h.push(
                         "" + $(this).text() + ""
                     ); 
                 });
             } 
             // remove appended headers by classname.
             $("tr.repated-header",table).remove(); 
             // loop all tr elements and insert a copy of the "headers"
             for(var i=0; i < table.tBodies[0].rows.length; i++) {
                 // insert a copy of the table head every 10th row
                 if((i%5) == 4) {
                     $("tbody tr:eq(" + i + ")",table).before(
                         $("").html(this.headers.join("")) 
                     );
                 }
             }
         }
     }); 
     // demo15 : 调用插件call the tablesorter plugin and assign widgets with id "zebra" (Default widget in the core) and the newly created "repeatHeaders"
     $("table").tablesorter({
         widgets: ['zebra','repeatHeaders']
     });         
 );
5. 注意事项
依赖项:jquery
meta数据插件: jQuery Metadata 2.1
分页插件:jQuery.tablesorter.pager.js
css,image 在blue skin 文件夹中可以找到
Demo 下载:https://pan.baidu.com/s/1hqwJpFQ
tablesorter 的使用的更多相关文章
- jQuery 表格排序插件 Tablesorter 使用
		jQuery 表格排序插件 Tablesorter 使用方式如下: 1.引入头文件(注意一定要把jQuery放在前面): <script src="lib/jquery-1.8.3.m ... 
- jquery.tablesorter.js  学习笔记
		jquery.tablesorter.js 一般情况下,表格数据的排序方式有两种,第一种是让后端服务将排序后的数据直接输出,另外一种方式就是使用客户端排序,而jquery.tablesorter.js ... 
- jQuery表格排序总成-tablesorter
		一个.进口单证 <script type="text/javascript" src="js/jquery.js"></script> ... 
- jQuery表格排序组件-tablesorter
		一.引入文件 <script type="text/javascript" src="js/jquery.js"></script> & ... 
- tablesorter周边文档
		一.简介: Tablesorter作用于一个标准的HTML表格(有THEAD,TBODY),实现静态排序:主要特点包括: (1) 多列排序: (2) 支持文本.URI地址.数值.货币.浮点数.IP地 ... 
- javascript:jQuery tablesorter 2.0
		https://mottie.github.io/tablesorter/docs/index.html 1.GridView <%@ Page Language="C#" ... 
- 表格排序(tablesorter)
		1.在html页面的head中引用 <script src="/static/Bootstrap/js/jquery/jquery.tablesorter.min.js"&g ... 
- jQuery表格排序(tablesorter)
		1.在html页面的head中引用 <script src="/static/Bootstrap/js/jquery/jquery.tablesorter.min.js"&g ... 
- jQuery html表格排序插件:tablesorter
		ablesort是一款很好用的jQuery表格排序插件. 支持多种数据类型排序,会自动识别表格内容数据类型,使用也非常方便. 使用jQuery tablesort实现html表格方法: 1. 下载jQ ... 
随机推荐
- 关于.NET  C#上传大文件的解决办法
			1.最近在解决问题的时候遇到如何将视频以及语音和图片上传到阿里云的服务器中.但是遇到一些大文件就导致无法进行上传. 2.在将图片进行上传到阿里云的时候先将文件转化为二进制文件,然后通过文件流 的形式进 ... 
- 基于爬取百合网的数据,用matplotlib生成图表
			爬取百合网的数据链接:http://www.cnblogs.com/YuWeiXiF/p/8439552.html 总共爬了22779条数据.第一次接触matplotlib库,以下代码参考了matpl ... 
- 让SpringMVC Restful API优雅地支持多版本
			好久没有更新博客,难得有空,记录一下今天写的一个小工具,供有需要的朋友参考. 在移动APP开发中,多版本接口同时存在的情况经常发生,通常接口支持多版本,有以下两种方式: 1.通过不同路径区分不同版本 ... 
- 使用 RxJS 实现一个简易的仿 Elm 架构应用
			使用 RxJS 实现一个简易的仿 Elm 架构应用 标签(空格分隔): 前端 什么是 Elm 架构 Elm 架构是一种使用 Elm 语言编写 Web 前端应用的简单架构,在代码模块化.代码重用以及测试 ... 
- Windows Server 2016-Powershell迁移FSMO角色
			上一章节我们讲到了通过Ntdsutil命令行进行FSMO角色迁移,本章开始之前我们先讨论一下有关FSMO角色放置建议: 建议将架构主机角色(Schema Master)和域命名主机角色(Domain ... 
- 【解决问题】SSH连不上Ubuntu虚拟机解决办法
			1. 安装openssh-client Ubuntu默认缺省安装了openssh-client,apt-get安装即可 sudo apt-get install openssh-client 2. 安 ... 
- visual studio code右侧的预览面板能关闭吗?
			https://segmentfault.com/q/1010000010082399 "editor.minimap.enabled":false 
- dedecms data文件夹外迁
			出于网站安全考虑,我们一般要把data文件夹迁移到网站根目录外面. dedecms data文件夹外迁方法: 1. 修改首页文件中配置文件路径 打开/index.php,把代码 if(!file_ex ... 
- 浏览器输入URL到响应页面的全过程
			B/S网络架构从前端到后端都得到了简化,都基于统一的应用层协议HTTP来交互数据,HTTP协议采用无状态的短链接的通信方式,通常情况下,一次请求就完成了一次数据交互,通常也对应一个业务逻辑,然后这次通 ... 
- 剑指offer第二天
			18.二叉树的镜像 操作给定的二叉树,将其变换为源二叉树的镜像. /** public class TreeNode { int val = 0; TreeNode left = null; Tree ... 
