Sortable Table

Discussion in 'Javascript' started by dmsc17454_2, Jul 16, 2004.

  1. dmsc17454_2

    dmsc17454_2 Guest

    dmsc17454_2, Jul 16, 2004
    #1
    1. Advertising

  2. dmsc17454_2

    dmsc17454_2 Guest

    dmsc17454_2 wrote in message
    > http://www.kryogenix.org/code/browser/sorttable/
    >
    > On this page there's a link to a "sorttable.js"
    > (http://www.kryogenix.org/code/browser/sorttable/sorttable.js), but when I
    > open it the code's unformatted, I guess this is because he saved it on a
    > different OS? So does anyone have a proper formatted version for a Windows
    > XP user?


    Well I managed to find this
    http://www.webmaster-toolkit.com/fr...genix.org/code/browser/sorttable/sorttable.js.

    Hopefully the output is correct :)
    dmsc17454_2, Jul 16, 2004
    #2
    1. Advertising

  3. dmsc17454_2

    dmsc17454_2 Guest

    Ok, slight help need with editing this "sorttable.js" file. I have no
    experience with Javascript

    // Work out a type for the column
    if (table.rows.length <= 1) return;
    var itm = ts_getInnerText(table.rows[1].cells[column]);
    sortfn = ts_sort_caseinsensitive;
    if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
    if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
    if (itm.match(/^[£$]/)) sortfn = ts_sort_currency;
    if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
    SORT_COLUMN_INDEX = column;
    var firstRow = new Array();
    var newRows = new Array();
    for (i=0;i<table.rows[0].length;i++) { firstRow = table.rows[0]; }
    for (j=1;j<table.rows.length;j++) { newRows[j-1] = table.rows[j]; }

    Basically, I want my dates to display like "12th May 2004" instead of
    "12/5/2004", I think the code above is to do with this.
    dmsc17454_2, Jul 16, 2004
    #3
  4. dmsc17454_2

    Joakim Braun Guest

    "dmsc17454_2" <> skrev i meddelandet
    news:QmRJc.877$...
    > Ok, slight help need with editing this "sorttable.js" file. I have no
    > experience with Javascript
    >
    > // Work out a type for the column
    > if (table.rows.length <= 1) return;
    > var itm = ts_getInnerText(table.rows[1].cells[column]);
    > sortfn = ts_sort_caseinsensitive;
    > if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) sortfn = ts_sort_date;
    > if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) sortfn = ts_sort_date;
    > if (itm.match(/^[£$]/)) sortfn = ts_sort_currency;
    > if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric;
    > SORT_COLUMN_INDEX = column;
    > var firstRow = new Array();
    > var newRows = new Array();
    > for (i=0;i<table.rows[0].length;i++) { firstRow = table.rows[0]; }
    > for (j=1;j<table.rows.length;j++) { newRows[j-1] = table.rows[j]; }
    >
    > Basically, I want my dates to display like "12th May 2004" instead of
    > "12/5/2004", I think the code above is to do with this.
    >


    No, as the comment indicates, it uses regular expressions to guess what kind
    of data the table contains based on how the content is formatted, then
    assigns an appropriate sorting function (date, currency or numeric).

    You might want to look up the javascript Date object. Probably you have to
    parse the table cell content yourself and use it to initialize a Date with.
    The Date can then be converted to text with various formatting options.

    Joakim Braun
    Joakim Braun, Jul 16, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henri =?ISO-8859-15?Q?Schom=E4cker?=
    Replies:
    1
    Views:
    286
    Henri =?ISO-8859-15?Q?Schom=E4cker?=
    Dec 17, 2005
  2. yccheok

    Sortable Java Tree Table

    yccheok, Dec 26, 2007, in forum: Java
    Replies:
    1
    Views:
    1,086
    Roedy Green
    Dec 27, 2007
  3. Peter Pei

    sortable table in python 3.0

    Peter Pei, Feb 8, 2009, in forum: Python
    Replies:
    1
    Views:
    415
    Martin v. Löwis
    Feb 8, 2009
  4. Andrus
    Replies:
    0
    Views:
    103
    Andrus
    Jul 2, 2003
  5. Replies:
    6
    Views:
    508
Loading...

Share This Page