Closed Thread Icon

Topic awaiting preservation: Table sorting with DOM (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8430" title="Pages that link to Topic awaiting preservation: Table sorting with DOM (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Table sorting with DOM <span class="small">(Page 1 of 1)</span>\

 
stinx
Bipolar (III) Inmate

From: London, UK
Insane since: Apr 2002

posted posted 12-11-2002 01:21

I put this together recently, and was wondering if anyone has an idea on how to improve it. http://stinx.no-ip.org/~rob/table_sort.htm (It's on the end of an adsl line, so don't be too surprised if the link fails)

There's a bit of a hack in there, since I wanted to support text nested inside anchor tags, and also because IE5.5 doesn't seem to support the dom properties. I haven't tried it in anything else except IE5.5 and Moz1.2

Comments / suggestion appreciated - I know I'm going to need this thing fully working for something.

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 12-11-2002 03:09

stinx, I didn't have time to look deep into the code but I can say that the capability you have there is *very* useful. I think it can be very useful for database outputs without having to reload everytime a new sorting order is needed. Great idea!

. . : slicePuzzle

reitsma
Maniac (V) Mad Scientist

From: the bigger bedroom
Insane since: Oct 2000

posted posted 12-11-2002 03:20

nice work.
very cool stuff, i'm quite impressed with this little fella.

...this could be especialyl useful when the database doesn't store views.

my advice is to send the data type with the function, so that it can sort numbers properly...

quick tip - if you were to "parseFloat('08')" it would sort it correctly.

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 12-11-2002 08:59

I've got a suggestion, you should place an up or down arrow image next to the column header according to the sort order. That would sweeten it up a bit

. . : slicePuzzle

Nevel
Bipolar (III) Inmate

From: Amsterdam
Insane since: Jun 2002

posted posted 12-11-2002 11:31

Looks neat indeed, this sort of script would be very powerful when implemented within a component(like Borland's TDataSetTableProducer). I must say I have encountered a script like this before, but unfortunately, I can't find the site .

Maybe you could reverse the vertical sorting algorithm when clicking on a header which is already selected..

stinx
Bipolar (III) Inmate

From: London, UK
Insane since: Apr 2002

posted posted 12-11-2002 17:21

Thanks for the feedback. I probably won't get round to improving it until I need to, but the ideas are sound.

The first priority for me would be to allow sorting numerically or alphanumerically (the parseFloat idea) - maybe even a couple of other methods. I had considered adding arrows, but I wanted it to be as inconspicuous as possible, to use on any layout. I suppose it depends on what it gets used for eventually.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-11-2002 18:30

Hmm... it would probably be best to put the TD's into an array, and then use array.sort with a custom sorting function that compares the values of the cells. That way, you're letting the browser do the sorting (which is a lot faster). Then, afterwards, you have to loop through the array and rearrange the table cells to be in the new positions. I'm not sure how that would be done, but there's probably a way.

stinx
Bipolar (III) Inmate

From: London, UK
Insane since: Apr 2002

posted posted 12-12-2002 10:55

Quite right about that, Slime ... how about this version? http://stinx.no-ip.org/~rob/table_sort2.htm

I have to declare a global var now, since the compare function in array.sort() only takes two arguments, but it does look a lot cleaner I daresay that the compare method (ascii or numeric), and the sort order (ascending or descending) will also have to be global.

Looping through the array and using appendChild() works, since it removes the element from it's place in the document first, and tags it on the end. This could be a fair amount of pointless work for a table that is already sorted.

[This message has been edited by stinx (edited 12-12-2002).]

« BackwardsOnwards »

Show Forum Drop Down Menu