Sortable Table

D

dmsc17454_2

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 :)
 
D

dmsc17454_2

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.
 
J

Joakim Braun

dmsc17454_2 said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top