问题与jQuery的tablesorter日期排序 [英] Problem with sorting dates with jquery tablesorter

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

问题描述

我使用tablesorter插件我在MVC .net应用程序中的表进行排序。我的大多数列都是字符串,我与他们有没有问题。既不用数字的。事情是我的datetime列,好像他们是字符串也越来越排序。他们得到排序是这样的:01/04/2009,02/02/2009,03/08/2009,等我从该视图中的模型获得的数据

我的电话是默认的:

  $(#表)的tablesorter()。

我试图指定,没有运气日期格式:

  $(#表)。的tablesorter({
            DATEFORMAT:'DD / MM / YYYY'});

奇怪的事情发生时,我手动随机日期键入静态表。它得到排序!但我的数据来自一个数据库调用,并投入示范,然后我itreate通过它,写TR与数据。

先谢谢了。

编辑:?难道是我创作的TR的方式进行相关的东西。

 <%的foreach(在型号VAR项){%GT;
&所述; TR>
&所述; TD>
<%= Html.En code(item.date)%GT;
< / TD>
< TD> ...< / TD>
< TD> ...< / TD>
< TD> ...< / TD>
< / TR>
<%}%GT;


解决方案

尝试添加的tablesorter解析器您的日期列。的tablesorter附带了shortDate,usLongDate和isoDate解析器。

  $(#表)。的tablesorter({
    标题:{colNum:{选机:shortDate'}}
});

,其中colNum与日期的列。我能找到在现场的tablesorter唯一的例子是这里。这也适用,如果是的tablesorter排序号码错了也是如此。还有其他的解析器,以及用于百分比,IP地址等等。就拿近源$ C ​​$ C月底一看,他们将在那里上市。

编辑:
在查看源$ C ​​$ C,dateformat选项出现仅被看我们,英国,DD / MM / YY或DD-MM-YY。当您尝试UK该怎么办?

I am using tablesorter plugin to sort my tables in an MVC .NET App. Most of my columns are strings and I'm having no problems with them. Neither with the numeric ones. The thing is my datetime columns are also getting sorted as if they were strings. They get sorted like this: 01/04/2009, 02/02/2009, 03/08/2009, etc. I obtain the data from the Model in that View.

My call is the default one:

$("#table").tablesorter();

I tried specifying dateformat with no luck:

$("#table").tablesorter({
            dateFormat: 'dd/mm/yyyy'});

The odd thing happens when I manually type a static table with random dates. It gets sorted! But my data comes from a DB call and is put into the Model, I then itreate through it and write tr's with the data.

Thanks in advance.

EDIT: Could it be something related with the way I create the tr's?

<% foreach (var item in Model) { %>
<tr>
<td>
<%= Html.Encode(item.date) %>
</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<% } %>

解决方案

Try adding a Tablesorter parser to your date column. Tablesorter comes with a parser for shortDate, usLongDate and isoDate.

$("#table").tablesorter({
    headers: { colNum: { sorter: 'shortDate'} }
});

where colNum is the column with the dates. The only example I could find on the tablesorter site is here. This also works if tablesorter is sorting numbers wrong as well. There are other parsers as well for percent, ip address and more. Take a look near the end of the source code and they'll be listed there.

Edit: In looking at the source code, the dateFormat option appears to be looking only for "us", "uk", "dd/mm/yy" or "dd-mm-yy". What happens when you try "uk"?

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

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