Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2008
    Posts
    105
    Thanks
    9
    Thanked 0 Times in 0 Posts

    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 10:16 PM.

  • #2
    Regular Coder
    Join Date
    Aug 2008
    Posts
    105
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Issue resolved.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •