I’d like to sort multi-column list without using a table. I know of solutions for single column lists but I can’t seem to find one that sorts on multiple Ul/columns while keeping the list/row items together.
Ultimately I’d like to make something similar to what dropbox has done for displaying files. Yes, Dropbox doesn’t use a sortable table. It’s a list instead of tr’s with a bunch of divs instead of td’s.
I don’t want to use a table because tables drive me crazy for styling purposes. Also, I don’t want to use a plugin (like tablesorter.js) because javascript has a built in sort() function so it can’t be that many lines of code.
Anyway, here is a nice single column demonstration taken from another SO question, and the original SO reference.
Basically I’d like to do what’s in the fiddle but be able to sort by names, and for example addresses, here’s a fiddle building upon this first fiddle where you can see where i’d like to go with this http://jsfiddle.net/trpeters1/De8Ku/955/. As you’ll notice, this fiddle can’t sort based on the address which is what I’d like find a solution for.
UPDATE
With many thanks to eterps (see below) now the fiddle can sort by multiple columns. I’d now like to next include sorting by date. Here is a fiddle which makes an attempt at this but doesn’t quite work. You’ll notice I tried to convert the innerHTML to a Date() object but this didn’t solve this problem.
http://jsfiddle.net/trpeters1/De8Ku/983/
In this fiddle, can someone help explain why the sorting of the dates is still just alpha/numerical and not by date?
Using the code you provided in your jsFiddle examples, you can add some identifying information to your span tags to differentiate the text into columns. Then you can use that information to do your sort. I altered the jsFiddle example to use a sorting function that will look at whichever column is specified. I’m sure there are more elegant ways of doing this, but it should get you started.
http://jsfiddle.net/De8Ku/976/
Here is the code in case the jsFiddle isn’t working or if someone want to edit this answer:
HTML:
JS: