Sorting a table possible?

M

MM

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
 
M

Michael Winter

MM wrote on 03 Dec 2003:
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
 

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,780
Messages
2,569,611
Members
45,285
Latest member
CryptoTaxxSoftware

Latest Threads

Top