<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 的使用的更多相关文章

  1. jQuery 表格排序插件 Tablesorter 使用

    jQuery 表格排序插件 Tablesorter 使用方式如下: 1.引入头文件(注意一定要把jQuery放在前面): <script src="lib/jquery-1.8.3.m ...

  2. jquery.tablesorter.js 学习笔记

    jquery.tablesorter.js 一般情况下,表格数据的排序方式有两种,第一种是让后端服务将排序后的数据直接输出,另外一种方式就是使用客户端排序,而jquery.tablesorter.js ...

  3. jQuery表格排序总成-tablesorter

    一个.进口单证 <script type="text/javascript" src="js/jquery.js"></script> ...

  4. jQuery表格排序组件-tablesorter

    一.引入文件 <script type="text/javascript" src="js/jquery.js"></script> & ...

  5. tablesorter周边文档

    一.简介: Tablesorter​作用于一个标准的HTML表格(有THEAD,TBODY),实现静态排序:主要特点包括: (1) 多列排序: (2) 支持文本.URI地址.数值.货币.浮点数.IP地 ...

  6. javascript:jQuery tablesorter 2.0

    https://mottie.github.io/tablesorter/docs/index.html 1.GridView <%@ Page Language="C#" ...

  7. 表格排序(tablesorter)

    1.在html页面的head中引用 <script src="/static/Bootstrap/js/jquery/jquery.tablesorter.min.js"&g ...

  8. jQuery表格排序(tablesorter)

    1.在html页面的head中引用 <script src="/static/Bootstrap/js/jquery/jquery.tablesorter.min.js"&g ...

  9. jQuery html表格排序插件:tablesorter

    ablesort是一款很好用的jQuery表格排序插件. 支持多种数据类型排序,会自动识别表格内容数据类型,使用也非常方便. 使用jQuery tablesort实现html表格方法: 1. 下载jQ ...

随机推荐

  1. offset / scroll / client Left / Top

    1.offsetHeight / Width (只读) offsetHeight:表示该元素在垂直方向占用的空间大小,包含元素的高度+上边框高度+下边框高度 offsetWidth:表示该元素在水平方 ...

  2. cocos2d-x代码阅读笔记 - 入口

    每一个C\C++程序都有一个非常有名的入口函数 main(),在Windows系统下,这个函数就变成了WinMain函数. 在cocos2d-x 2.0.4的Windows版本中,main函数非常简单 ...

  3. jenkins入门系列之一 jenkins的安装

    Jenkins是一个CI(持续集成环境)工具.它可以根据设定持续定期编译,运行相应代码:运行UT或集成测试:将运行结果发送至邮件,或展示成报告... 这样做的最终目的是: 让项目保持健康的状态.如果任 ...

  4. AMD && CMD

    前言 JavaScript初衷:实现简单的页面交互逻辑,寥寥数语即可: 随着web2.0时代的到来,Ajax技术得到广泛应用,jQuery等前端库层出不穷,前端代码日益膨胀 问题: 这时候JavaSc ...

  5. 六、BeautifulSoup4------自动登录网站(手动版)

    每天一个小实例:(按照教学视频上自动登录的网站,很容易就成功了.自已练习登录别的网站,问题不断) 这个自己分析登录boss直聘.我用了一下午的时间,而且还是手动输入验证码,自动识别输入验证码的还没成功 ...

  6. 共享数据的包含const

    1.常引用:被引用的对象不能被更新 使用:const 类型名 &引用对象    如const int &a; 2.常对象:必须进行初始化,并且对象不能改变    使用:类名 const ...

  7. Sublime Text3 快捷键汇总及设置快捷键配置环境变量

    Ctrl+D 选词 (反复按快捷键,即可继续向下同时选中下一个相同的文本进行同时编辑)Ctrl+G 跳转到相应的行Ctrl+J 合并行(已选择需要合并的多行时)Ctrl+L 选择整行(按住-继续选择下 ...

  8. R语言-来自Prosper的贷款数据探索

    案例分析:Prosper是美国的一家P2P在线借贷平台,网站撮合了一些有闲钱的人和一些急用钱的人.用户若有贷款需求,可在网站上列出期望数额和可承受的最大利率.潜在贷方则为数额和利率展开竞价. 本项目拟 ...

  9. SSE图像算法优化系列十七:多个图像处理中常用函数的SSE实现。

    在做图像处理的SSE优化时,也会经常遇到一些小的过程.数值优化等代码,本文分享一些个人收藏或实现的代码片段给大家. 一.快速求对数运算 对数运算在图像处理中也是个经常会遇到的过程,特备是在一些数据压缩 ...

  10. 在 ASP.NET Core 项目中实现小写的路由URL

    在 ASP.NET MVC 早期版本中,我们可以通过在应用的 RegisterRoutes 方法中设置 routes.LowercaseUrls = true ; 来将页面的 URL 链接转小写.在 ...