Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-10-2009, 06:05 PM   PM User | #1
sethwb
Regular Coder

 
Join Date: Aug 2008
Posts: 105
Thanks: 9
Thanked 0 Times in 0 Posts
sethwb is an unknown quantity at this point
jQuery table sorter - need help customizing date parser

Goal: Implement jQuery Sort Table with custom date format: "10 October 2009"

Using: http://tablesorter.com/docs/ with jQuery latest

My attempt at altering the date parser (currently not working, but not throwing errors):


Code:
var monthNames = {}; 
      monthNames["Januari"] = "01"; 
      monthNames["Februari"] = "02"; 
      monthNames["Maart"] = "03"; 
      monthNames["April"] = "04"; 
      monthNames["Mei"] = "05"; 
      monthNames["Juni"] = "06"; 
      monthNames["Juli"] = "07"; 
      monthNames["Augustus"] = "08"; 
      monthNames["September"] = "09"; 
      monthNames["October"] = "10"; 
      monthNames["November"] = "11"; 
      monthNames["December"] = "12"; 
      $.tablesorter.addParser({  
        id: 'datewithmonthname',  
        is: function(s) {  
            return false;  
        },  
        format: function(s) {  
            var hit = s.match(/^(\d{1,2})[ ](\w+)[ ](\d{4})$/); 
            //console.log(hit); 
            var m = hit[2]; 
            m = monthNames[m]; 
            var d = "0" + hit[1]; 
            d = d.substr(d.length - 2); 
            var y = hit[3]; 
            //console.log("" + y + m + d); 
            //alert("" + y + m + + d);
            return "" + y + m + + d; 
        },  
        type: 'numeric'  
    });  
 
      $("#oldArticles").tablesorter({
            headers: {  
                0: {  
                    sorter:'datewithmonthname'  
                }  
            }  
        });

By default table sorter tries to sort my date field by the day (the first number it encounters).

Since I've updated the code it doesn't seem to follow any specific pattern, things just get jumbled around.


Please help!!!!


p.s.
I just want to add that the Month names are in Dutch and fully spelled out:

10 Augustus 2009

Last edited by sethwb; 11-10-2009 at 09:16 PM..
sethwb is offline   Reply With Quote
Old 11-10-2009, 09:27 PM   PM User | #2
sethwb
Regular Coder

 
Join Date: Aug 2008
Posts: 105
Thanks: 9
Thanked 0 Times in 0 Posts
sethwb is an unknown quantity at this point
Issue resolved.
sethwb is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:36 AM.


Advertisement
Log in to turn off these ads.