`

jquery table排序

阅读更多

今天看了一篇文章,是介绍JQ中的排序问题。用到的是它的一个插件tablesorter.js,更丰富的话还会用到jquery-latest.js以及jquery.tablesorter.pager.js。
用到的语句是这样的:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function() {   
  2. $("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} );   
  3. }   
  4. )    

有点不太明白,查了下sortList的参数,但是没有任何结果。后来在一位大哥的指点下找到了答案:
排序列表[0,0][1,0],按第一列,第二列进行升序排序,[列索引,排序方向] 0 asc(升序) 1 desc(降序)。
还有一些其他的参数:

第一部分

禁止第二列.每三列进行排序

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $("myTable").tablesorter({   
  3. // pass the headers argument and assing a object   
  4. headers: {   
  5. // assign the secound column (we start counting zero)   
  6. 1: {   
  7. // disable it by setting the property sorter to false   
  8. sorter: false},   
  9. // assign the third column (we start counting zero)   
  10. 2: {   
  11. // disable it by setting the property sorter to false   
  12. sorter: false}   
  13. }   
  14. });   
  15. });   

使用TH更像一个按钮

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $("#myTable").tableSorter(   
  3. {cancelSelection:true}   
  4. );   
  5. });    

强制某列排序后不能动,其它列根据该列进行排序

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. // call the tablesorter plugin\   
  3. $("myTable").tablesorter({   
  4. // set forced sort on the fourth column and i decending order.   
  5. sortForce: [[0,0]]}   
  6. );   
  7. });     

按键的更换

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. // call the tablesorter plugin   
  3. $("table").tablesorter({   
  4. // change the multi sort key from the default shift to alt button   
  5. sortMultiSortKey: ‘altKey’   
  6. });   
  7. });    

顺便查到一些ui的其他插件:

ui.draggable.ext.js

用法:文件载入后,可以拖拽class = “block”的层

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”.block”).draggable();   
  3. });   

draggable(options)可以跟很多选项

选项说明:http://docs.jquery.com/UI/Draggables/draggable#options

选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/draggable.html

Droppables:

所需要文件,drag drop

ui.mouse.js

ui.draggable.js

ui.draggable.ext.js

ui.droppable.js

ui.droppable.ext.js

用法:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”.block”).draggable({helper: ‘clone’});   
  3. $(”.drop”).droppable({   
  4. accept: “.block”,   
  5. activeClass: ‘droppable-active’,  
  6. hoverClass: ‘droppable-hover’,   
  7. drop: function(ev, ui) {   
  8. $(this).append(”<br>Dropped!”);  
  9. }     
  10. });     
  11. });    

选项说明:http://docs.jquery.com/UI/Droppables/droppable#options

选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/droppable.html

Sortables排序:

所需要的文件

jquery.dimensions.js

ui.mouse.js

ui.draggable.js

ui.droppable.js

ui.sortable.js

用法:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”#myList”).sortable({});   
  3. });   

dimensions文档http://jquery.com/plugins/project/dimensions

选项说明:http://docs.jquery.com/UI/Sortables/sortable#options

选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.sortable.html

Selectables 选择:

所需要的文件

jquery.dimensions.js

ui.mouse.js

ui.draggable.js

ui.droppable.js

ui.selectable.js

用法:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”#myList”).selectable();   
  3. });    

选项说明:http://docs.jquery.com/UI/Selectables/selectable#options

选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/selectable.html

Resizables改变大小:

所需要的文件 ,此例子需要几个css文件

jquery.dimensions.js

ui.mouse.js

ui.resizable.js

用法:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”#example”).resizable();   
  3. });  

CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css

选项说明:http://docs.jquery.com/UI/Resizables/resizable#options

选项实例:http://dev.jquery.com/view/trunk … s/ui.resizable.html

第二部分:互动效果:

Accordion 折叠菜单:

所需要的文件:

ui.accordion.js

jquery.dimensions.js

用法:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”#example”).accordion();   
  3. });   

CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css

选项说明:http://docs.jquery.com/UI/Accordion/accordion#options

选项实例:http://dev.jquery.com/view/trunk/plugins/accordion/?p=1.1.1

dialogs 对话框:

所需要的文件:

jquery.dimensions.js

ui.dialog.js

ui.resizable.js

ui.mouse.js

ui.draggable.js

用法:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”#example”).dialog();   
  3. });    

CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css

选项说明:http://docs.jquery.com/UI/Dialog/dialog#options

选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/dialog.html

sliders 滑动条:

所需要的文件

jquery.dimensions.js

ui.mouse.js

ui.slider.js

用法:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”#example”).slider();   
  3. });    

CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css

选项说明:http://docs.jquery.com/UI/Slider/slider#options

选项实例:http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.slider.html

Tablesorter表格排序:

所需要的文件

ui.tablesorter.js

用法:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”#example”).tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']});   
  3. });   

CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css

选项说明:http://docs.jquery.com/Plugins/Tablesorter/tablesorter#options

选项实例:http://tablesorter.com/docs/#Demo

tabs页签(对IE支持不是很好):

所需要的文件

ui.tabs.js

用法:

JavaScript Code复制内容到剪贴板
  1. $(document).ready(function(){   
  2. $(”#example > ul”).tabs();   
  3. });    

CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css

选项说明:http://docs.jquery.com/UI/Tabs/tabs#initialoptions

选项实例:http://dev.jquery.com/view/trunk/plugins/ui/tests/tabs.html

tabs ext http://stilbuero.de/jquery/tabs_3/rotate.html

第三部分:效果:

Shadow 阴影

实例http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.shadow.html

Magnifier 放大

实例http://dev.jquery.com/view/trunk/plugins/ui/demos/ui.magnifier.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics