JQuery tablesorter问题 [英] JQuery tablesorter problem

查看:120
本文介绍了JQuery tablesorter问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用JQuery tablesorter 插件时遇到了一些问题。如果你点击一个列标题,它应该按这个列对数据进行排序,但是有几个问题:


  1. 行是没有正确排序(1,1,2183,236)

  2. 总排包含在排序中

关于(2),我不能轻易地将总行移动到表格页脚,因为HTML是由 tablesorter教程中最简单示例中所示的完全相同的JavaScript。



实际上,只有一行JS代码,即:

 < body onload =jQuery('#communityStats')。tablesorter();> 

在此先感谢您,
Don

解决方案

第一个问题是由于表分类器自动将列检测到文本列(可能是因为空单元格)。要解决此问题,请使用此代码初始化tablesorter,并根据数据将所有字段设置为数字或货币:

 << ; script type =text / javascript> 
jQuery(document).ready(function()
{
jQuery(#communityStats)。tablesorter({
headers:{2:{sorter:'digit'} ,
3:{分拣机:'digit'},
4:{分拣机:'digit'},
5:{分拣机:'digit'},
6: sorter:'digit'},
7:{sorter:'digit'},
8:{sorter:'currency'},
9:{sorter:'currency'},
10:{sorter:'currency'},
11:{sorter:'currency'}
}
});
});
< / script>


I'm having a couple of problems with the JQuery tablesorter plugin. If you click on a column header, it should sort the data by this column, but there are a couple of problems:

  1. The rows are not properly sorted (1, 1, 2183, 236)
  2. The total row is included in the sort

Regarding (2), I can't easily move the total row to a table footer, because the HTML is generated by the displaytag tag library over which I have limited control.

Regarding (1), I don't understand why the sort doesn't work as I've used exactly the same JavaScript shown in the simplest example in the tablesorter tutorials.

In fact, there's only a single line of JS code, which is:

<body onload="jQuery('#communityStats').tablesorter();">

Thanks in advance, Don

解决方案

The first problem is due to the fact that the table sorter auto detects the column to a 'text'-column (probably because the empty cells). To solve this use this code to initialize the tablesorter and set all the field to either digit or currency depending on the data:

<script type="text/javascript" >
jQuery(document).ready(function() 
{ 
    jQuery("#communityStats").tablesorter({ 
        headers: { 2: { sorter:'digit' } , 
                   3: { sorter:'digit' } ,
                   4: { sorter:'digit' } ,
                   5: { sorter:'digit' } ,
                   6: { sorter:'digit' } ,
                   7: { sorter:'digit' } ,
                   8: { sorter:'currency' } ,
                   9: { sorter:'currency' } ,
                   10: { sorter:'currency' } ,
                   11: { sorter:'currency' } 
                 } 
    }); 
});
</script>

这篇关于JQuery tablesorter问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆