Sortable Table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dmsc17454_2

    Sortable Table



    On this page there's a link to a "sorttable. js"
    (http://www.kryogenix.org/code/browse.../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?


  • dmsc17454_2

    #2
    Re: Sortable Table


    dmsc17454_2 wrote in message[color=blue]
    > http://www.kryogenix.org/code/browser/sorttable/
    >
    > On this page there's a link to a "sorttable. js"
    > (http://www.kryogenix.org/code/browse.../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?[/color]

    Well I managed to find this
    http://www.webmaster-toolkit.com/fro...2Fsorttable.js.

    Hopefully the output is correct :)


    Comment

    • dmsc17454_2

      #3
      Re: Sortable Table

      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.len gth <= 1) return;
      var itm = ts_getInnerText (table.rows[1].cells[column]);
      sortfn = ts_sort_caseins ensitive;
      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_currenc y;
      if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric ;
      SORT_COLUMN_IND EX = column;
      var firstRow = new Array();
      var newRows = new Array();
      for (i=0;i<table.ro ws[0].length;i++) { firstRow[i] = table.rows[0][i]; }
      for (j=1;j<table.ro ws.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.


      Comment

      • Joakim Braun

        #4
        Re: Sortable Table

        "dmsc17454_ 2" <dmsc17454_2@bl ueyonder.co.uk> skrev i meddelandet
        news:QmRJc.877$ _75.9770101@new s-text.cableinet. net...[color=blue]
        > 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.len gth <= 1) return;
        > var itm = ts_getInnerText (table.rows[1].cells[column]);
        > sortfn = ts_sort_caseins ensitive;
        > 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_currenc y;
        > if (itm.match(/^[\d\.]+$/)) sortfn = ts_sort_numeric ;
        > SORT_COLUMN_IND EX = column;
        > var firstRow = new Array();
        > var newRows = new Array();
        > for (i=0;i<table.ro ws[0].length;i++) { firstRow[i] = table.rows[0][i]; }
        > for (j=1;j<table.ro ws.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.
        >[/color]

        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


        Comment

        Working...