HighDots Forums  

Sorting a table possible?

Javascript JavaScript language (comp.lang.javascript)


Discuss Sorting a table possible? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
MM
 
Posts: n/a

Default Sorting a table possible? - 12-03-2003 , 02:57 AM






Hi there,

Is it at all possible to sort the contents of a table (ordinary html
<table><tr><td>...</td></tr></table>) using javascript? What I want is to be
able to select, for example by klicking a button or checking a radio button,
whether the table shall be sorted by column 1 och 2. Even if the table has
three or more columns I'm only interested in sorting (increasingly) by first
or second.

I would be nice if I did not have to change my table contents (I already
have it, 87 rows, 9 columns, with lots of links and stuff) into say an
array, but if that is the only way then maybe I will have to accept that.

So, any ideas?

Many thanks in advance,

MM




Reply With Quote
  #2  
Old   
Michael Winter
 
Posts: n/a

Default Re: Sorting a table possible? - 12-03-2003 , 07:19 AM






MM wrote on 03 Dec 2003:

Quote:
Hi there,

Is it at all possible to sort the contents of a table (ordinary
html <table><tr><td>...</td></tr></table>) using javascript?
What I want is to be able to select, for example by klicking a
button or checking a radio button, whether the table shall be
sorted by column 1 och 2. Even if the table has three or more
columns I'm only interested in sorting (increasingly) by first
or second.

I would be nice if I did not have to change my table contents (I
already have it, 87 rows, 9 columns, with lots of links and
stuff) into say an array, but if that is the only way then maybe
I will have to accept that.
I think the most efficient way would be to read the table into a
multidimensional array, sort that, then write it back out using DOM
methods.

You could do it more or less in-place, but you'd have to do the sort
manually, as apposed to using the Array.sort() method.

Of course, this won't work in older browsers.

Mike

--
Michael Winter
M.Winter (AT) blueyonder (DOT) co.uk.invalid (remove ".invalid" to reply)


Reply With Quote
  #3  
Old   
F. Da Costa
 
Posts: n/a

Default Re: Sorting a table possible? - 12-03-2003 , 03:33 PM



Just have a look here.

http://webfx.eae.net/dhtml/sortabletable/demos.html
Helped me a lot

Cheers
Fermin DCG

MM wrote:

Quote:
Hi there,

Is it at all possible to sort the contents of a table (ordinary html
table><tr><td>...</td></tr></table>) using javascript? What I want is to be
able to select, for example by klicking a button or checking a radio button,
whether the table shall be sorted by column 1 och 2. Even if the table has
three or more columns I'm only interested in sorting (increasingly) by first
or second.

I would be nice if I did not have to change my table contents (I already
have it, 87 rows, 9 columns, with lots of links and stuff) into say an
array, but if that is the only way then maybe I will have to accept that.

So, any ideas?

Many thanks in advance,

MM





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.