[jQuery] Re: tablesorter add date parser
Is there a quick way to have this parser available for any table i add the tablesorter to, or do i have to add the tablesorter parser each time the tablesorter is used. On one of the pages i have the tablesorter code that applies the parser and the parser code above it.. if i remove the parser code and stick it up in my header, for some reason the parser doesnt function at all. Maybe im getting some js problems i am not catching or seeing.. will see... On Sep 4, 2:35 pm, dduck1934 [EMAIL PROTECTED] wrote: Thank you! That seemed to do the trick. I appreciate it greatly. Matthew On Sep 4, 1:59 pm, MorningZ [EMAIL PROTECTED] wrote: btw, the AlphaNum has zero to do with this post, that was from a previous post i helped out on. i should have removed that to make this post more clear
[jQuery] Re: tablesorter add date parser
This is SUPER quick and dirty, but appears to be working (btw: rather than hacking up the tablesorter.js file for sort rules, it's 1000x better to add a parser that we if he releases a new version, you don't have to re-hack up the code) !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml; head titleUntitled Page/title script type=text/javascript src=http://tablesorter.com/jquery- latest.js/script script type=text/javascript src=http://tablesorter.com/ jquery.tablesorter.js/script script type=text/javascript $(document).ready(function() { var months = {}; months[JAN] = 01; months[FEB] = 02; months[MAR] = 03; months[APR] = 04; months[MAY] = 05; months[JUN] = 06; months[JUL] = 07; months[AUG] = 08; months[SEP] = 09; months[OCT] = 10; months[NOV] = 11; months[DEC] = 12; $.tablesorter.addParser({ id: 'AlphaNum', is: function(s) { return false; }, format: function(s) { s = '' + s; s = s.toUpperCase(); if (isNaN(s)) { return 'ZZ' + s; } else { return 'AA' + PadString(s, ''); } }, type: 'text' }); $.tablesorter.addParser({ id: 'DD-MMM-YY', is: function(s) { return false; }, format: function(s) { s = '' + s; //Make sure it's a string var hit = s.match(/(\d{2})-([A-Za-z]{3})-(\d{2})/); if (hit hit.length == 4) { return hit[3] + months[hit[2].toUpperCase()] + hit[1]; } else { return s; } }, type: 'text' }); $(#myTable).tablesorter({ headers: { 0: { sorter: 'AlphaNum' }, 6: { sorter: 'DD-MMM-YY' } } }); }); function PadString(str, pad) { if (pad == undefined) { pad = 00; } str = + pad + str; return Right(str, pad.length); } function Right(str, n) { if (n = 0) { return ''; } else if (n String(str).length) { return str; } else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } /script style type=text/css body { font-size: 10px; font-family: Verdana; } #myTable { } #myTable th { background-color: #c0c0c0; } /style /head body divTablesorter custom Sort: /div div table id=myTable thead tr thColumn A/th thLast Name/th thFirst Name/th thEmail/th thDue/th thWeb Site/th thDate/th /tr /thead tbody tr td1/td tdSmith/td tdJohn/td td[EMAIL PROTECTED]/td td$50.00/td tdhttp://www.jsmith.com/td td04-SEP-08/td /tr tr td15/td tdBach/td tdFrank/td td[EMAIL PROTECTED]/td td$50.00/td tdhttp://www.frank.com/td td09-JUN-08/td /tr tr td8/td tdDoe/td tdJason/td td[EMAIL PROTECTED]/td td$100.00/td tdhttp://www.jdoe.com/td td22-OCT-07/td /tr tr tdSmith/td tdConway/td tdTim/td td[EMAIL PROTECTED]/td td$50.00/td tdhttp://www.timconway.com/td td01-APR-08/td /tr tr tdYouk/td tdJones/td tdBob/td td[EMAIL PROTECTED]/td td$47.00/td tdhttp://www.espn.com/td td11-MAR-07/td /tr /tbody /table /div /body /html
[jQuery] Re: tablesorter add date parser
btw, the AlphaNum has zero to do with this post, that was from a previous post i helped out on. i should have removed that to make this post more clear
[jQuery] Re: tablesorter add date parser
This is SUPER quick and dirty, but appears to be working (btw: rather than hacking up the tablesorter.js file for sort rules, it's 1000x better to add a parser that way if he releases a new version, you don't have to re-hack up the code) !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml; head titleUntitled Page/title script type=text/javascript src=http://tablesorter.com/ jquery- latest.js/script script type=text/javascript src=http://tablesorter.com/ jquery.tablesorter.js/script script type=text/javascript $(document).ready(function() { var months = {}; months[JAN] = 01; months[FEB] = 02; months[MAR] = 03; months[APR] = 04; months[MAY] = 05; months[JUN] = 06; months[JUL] = 07; months[AUG] = 08; months[SEP] = 09; months[OCT] = 10; months[NOV] = 11; months[DEC] = 12; $.tablesorter.addParser({ id: 'DD-MMM-YY', is: function(s) { return false; }, format: function(s) { s = '' + s; //Make sure it's a string var hit = s.match(/(\d{2})-([A-Za-z]{3})- (\d{2})/); if (hit hit.length == 4) { return hit[3] + months[hit[2].toUpperCase()] + hit[1]; } else { return s; } }, type: 'text' }); $(#myTable).tablesorter({ headers: { 6: { sorter: 'DD-MMM-YY' } } }); }); /script style type=text/css body { font-size: 10px; font-family: Verdana; } #myTable { } #myTable th { background-color: #c0c0c0; } /style /head body divTablesorter custom Sort: /div div table id=myTable thead tr thColumn A/th thLast Name/th thFirst Name/th thEmail/th thDue/th thWeb Site/th thDate/th /tr /thead tbody tr td1/td tdSmith/td tdJohn/td td[EMAIL PROTECTED]/td td$50.00/td tdhttp://www.jsmith.com/td td04-SEP-08/td /tr tr td15/td tdBach/td tdFrank/td td[EMAIL PROTECTED]/td td$50.00/td tdhttp://www.frank.com/td td09-JUN-08/td /tr tr td8/td tdDoe/td tdJason/td td[EMAIL PROTECTED]/td td$100.00/td tdhttp://www.jdoe.com/td td22-OCT-07/td /tr tr tdSmith/td tdConway/td tdTim/td td[EMAIL PROTECTED]/td td$50.00/td tdhttp://www.timconway.com/td td01-APR-08/td /tr tr tdYouk/td tdJones/td tdBob/td td[EMAIL PROTECTED]/td td$47.00/td tdhttp://www.espn.com/td td11-MAR-07/td /tr /tbody /table /div /body /html
[jQuery] Re: tablesorter add date parser
Thank you! That seemed to do the trick. I appreciate it greatly. Matthew On Sep 4, 1:59 pm, MorningZ [EMAIL PROTECTED] wrote: btw, the AlphaNum has zero to do with this post, that was from a previous post i helped out on. i should have removed that to make this post more clear