English 中文(简体)
表格,按日期正确打折
原标题:tablesorter, wont sort by date correctly

如果存在白色空间,则各表层是否采取不同的做法?

表格的Im 粗略新,但我很快被要求将其添加到客户网站(具体来说,允许他们按日期进行分类)。 如我所知,日期(例如2012年5月14日)为案文,因此,我需要增加一个词句,将其改为数字,以便适当分类。 (例如,14052012年)

我(目前使用其他开发商撰写的法典)居住在表格中。

$.tablesorter.addParser({
id:  dayMonthYear ,
is: function(s) {
    return false;
},
format: function(s) {           

    var date = s.match(/^(d{1,2})[ ](w{3})[ ](d{4})$/);
    var day = String(date[1]);
    if (day.length == 1) {
        day = "0" + day;
    }        

    var month = monthNames[date[2]];
    var year = date[3];
    var sortableDate =    + year + month + day;
    return sortableDate;
},
type:  numeric   
});

var monthNames = {};
monthNames["Jan"] = "01";
monthNames["Feb"] = "02";
monthNames["Mar"] = "03";
monthNames["Apr"] = "04";
monthNames["May"] = "05";
monthNames["Jun"] = "06";
monthNames["Jul"] = "07";
monthNames["Aug"] = "08";
monthNames["Sep"] = "09";
monthNames["Oct"] = "10";
monthNames["Nov"] = "11";
monthNames["Dec"] = "12";

我也把这段话放在了html网页上。

$("table#searchresults").tablesorter ({
    headers: {
        0: {sorter: dayMonthYear }
    }
});

尽管我已经看到这一法典发挥作用,但似乎在为我工作。 本月仍为案文。

任何想法? 我所能看到的是,工作台和我的工地之间有别的唯一事情是,桌上有白空间的载荷,这是否是一个问题?


EDIT: Just found this, http://beau Brand.com/blog/custom-date-sorting-for-jquery-tablesorter-plugin/, see knowledge to the above Code. 希望有助于......

问题回答

工作。 phe

$.tablesorter.addParser({
id:  dayMonthYear ,
is: function(s) {
    return false;
},
format: function(s) {       

    s = $.trim(s.replace(/s+/g,    ));


    var date = s.match(/^(d{1,2})[ ](w{3})[ ](d{4})$/);
    var day = String(date[1]);
    if (day.length == 1) { day = "0" + day;}        
    var month = monthNames[date[2]];
    var year = date[3];

    return sortableDate =    + year + month + day;
},
type:  numeric   
});
var monthNames = {};
monthNames["Jan"] = "01";
monthNames["Feb"] = "02";
monthNames["Mar"] = "03";
monthNames["Apr"] = "04";
monthNames["May"] = "05";
monthNames["Jun"] = "06";
monthNames["Jul"] = "07";
monthNames["Aug"] = "08";
monthNames["Sep"] = "09";
monthNames["Oct"] = "10";
monthNames["Nov"] = "11";
monthNames["Dec"] = "12";




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签