By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Sorting a table possible?

P: n/a
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

Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #2

P: n/a
Just have a look here.

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

Cheers
Fermin DCG

MM wrote:
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


Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.