jQuery表格排序(tablesorter)
2016-05-31 16:17
330 查看
1.在html页面的head中引用 <script src="/static/Bootstrap/js/jquery/jquery.tablesorter.min.js"></script>
2.在.js文件中加载tablesorter:
$("table tbody").append(html);
$("table").trigger("update"); table是js自动生成的,需要在生成时添加这句
3.在.js文件中对需要排序的表格调用tablesorter()方法:
$('#tresult').tablesorter({headers:{0:{sorter:false}}}); #不能对第一列进行排序
http://plugins.jquery.com/tablesorter/ (download tablesorter.js)
from:http://tablesorter.com/docs/example-empty-table.html#
2.在.js文件中加载tablesorter:
$("table tbody").append(html);
$("table").trigger("update"); table是js自动生成的,需要在生成时添加这句
3.在.js文件中对需要排序的表格调用tablesorter()方法:
$('#tresult').tablesorter({headers:{0:{sorter:false}}}); #不能对第一列进行排序
$(document).ready(function() { $("table").tablesorter(); $("#append").click(function() { // add some html var html = "<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>"; html += "<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>"; html += "<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>"; // append new html to table body $("table tbody").append(html); // let the plugin know that we made a update $("table").trigger("update"); // set sorting column and direction, this will sort on the first and third column var sorting = [[2,1],[0,0]]; // sort on the first column $("table").trigger("sorton",[sorting]); return false; }); });
http://plugins.jquery.com/tablesorter/ (download tablesorter.js)
from:http://tablesorter.com/docs/example-empty-table.html#
相关文章推荐
- jquery 遍历form 表单
- jQuery效果
- jquery的each()详细介绍 -
- Jquery 插件学习笔记
- Jquery EasyUI后台实例 - undefined? - 博客园
- jQuery MiniUI - 快速开发WebUI
- Live Demo - jQuery EasyUI
- 如何自己开发一款js或者jquery插件
- JQuery中的动画整理
- jQuery 中 jQuery(function(){})与(function(){})(jQuery) 的区别
- JQuery实现动画效果
- jquery mobile中动态设置Checkbox选中、不选中
- jQuery使用经验小技巧(推荐)
- jQuery插件之路(二)——轮播
- Json对象与Json字符串互转(4种转换方式) jquery 以及 js 的方式
- Jquery+CSS实现分页
- 利用jquery简单实现返回顶部功能
- Jquery图片上传组件,支持多文件上传
- jQuery.lazyload
- jquery jsonp 跨域