Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7670351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:48:11+00:00 2026-05-31T15:48:11+00:00

I’d like to sort multi-column list without using a table. I know of solutions

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:48:12+00:00Added an answer on May 31, 2026 at 3:48 pm

    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:

    <input type="button" id="test" value="sort by names"/>
    <input type="button" id="test1" value="sort by address"/>
    
    <ul id="list">
       <li ><span class="name">peter</span><span class="address"> 812 jones st.</span></li>
       <li><span class="name">zack</span><span class="address"> 512 jones st.</span></li>
       <li><span class="name">alex</span><span class="address"> 712 jones st.</span></li>
       <li><span class="name">sue</span><span class="address"> 112 jones st.</span></li>
       <li><span class="name">jenny</span><span class="address"> 912 jones st.</span></li>
    </ul>
    

    JS:

    function sortUnorderedList(ul, sortDescending, sortClass) {
        if (typeof ul == "string") {
            ul = document.getElementById(ul);
        }
    
        var lis = ul.getElementsByTagName("LI");
        var vals = [];
    
        // Instead of filling an array with list items, 
        // create an array of objects that contain the list item itself, 
        // and the value from the sort-by column
        for (var i = 0, l = lis.length; i < l; i++) {
            vals.push({
                sortFieldVal: lis[i].getElementsByClassName(sortClass)[0].innerText,
                val: lis[i].innerHTML
            });
        }
    
        // Use a sort function to compare string values of sortFieldVal for each item
        vals.sort(function(a, b) {
            var nameA=a.sortFieldVal.toLowerCase(), nameB=b.sortFieldVal.toLowerCase()
            if (nameA < nameB) //sort string ascending
            return -1 
            if (nameA > nameB)
            return 1
            return 0 //default return value (no sorting)
        });
    
        if (sortDescending) vals.reverse();
    
        for (var i = 0, l = lis.length; i < l; i++)
        lis[i].innerHTML = vals[i].val;
    }
    
    window.onload = function() {
        var desc = false;
        document.getElementById("test").onclick = function() {
            sortUnorderedList("list", desc, "name");
            desc = !desc;
            return false;
        }
    
        document.getElementById("test1").onclick = function() {
            sortUnorderedList("list", desc, "address");
            desc = !desc;
            return false;
        }
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.