www.webdeveloper.com
Results 1 to 7 of 7

Thread: Order by [row]

  1. #1
    Join Date
    Nov 2013
    Posts
    18

    Order by [row]

    Hi!

    So after a few hours of research I have gotten no where with this.
    What I want to do is if I got a list with with 4 headlines called id, name, category, subcategory. If i press on ID I want the list to order by id ASC, press again DESC. If I press name same thing but with name.

    Thank you in advance!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,408
    I'd probably send the data to the page as a JSON object, then let JavaScript take care of the display/sorting (JQuery should have all the methods you need).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2013
    Posts
    18
    Thanks for the qucik answer.
    I don't seem to find anything about it when researching. Don't know where to begin .. :/

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,408
    Looks like some useful stuff if you Google for "jquery table sorting". Or just try searching the JavaScript forum on this site, perhaps? (I'm a JavaScript hack: I know enough to figure out what to search for and can end up getting something to work, but am nowhere near being a JavaScript "guru".)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Nov 2013
    Posts
    18
    Your information have gotten me much closer, thanks! But do you recommend using the jquery plugin called DataTable or build your own?

  6. #6
    Join Date
    May 2014
    Posts
    1,051
    My own JS library is designed to handle things like this out of the box by attaching a 'uSort' method to TBODY elements.

    http://www.elementalsjs.com/Element.[TBODY].uSort

    It's currently in early beta and there's a major compatibility bug with legacy IE (that came about from my taking bad advice from someone) that I need to fix, but as you can see on that page implementing it is pretty simple compared to other methods. You could easily eventAdd a handler to your THEAD's TH (assuming you have proper document structure) to say to sort by that field and reverse the order if already sorted by that one.

    I'm fixing that legacy IE bug right now, but when I'm done I'll toss together an example of that in action for you. It's a lot leaner a solution than jQuery (to the tune of 1/8th the size once compressed) and assuming your table is well formed should be pretty speedy too.
    Java is to JavaScript as Ham is to Hamburger.

  7. #7
    Join Date
    May 2014
    Posts
    1,051
    ... and here it is; and thanks for the inspiration; doing this squashed a whole slew of bugs in my library.

    http://www.cutcodedown.com/for_other.../template.html

    as with all my examples the directory:

    http://www.cutcodedown.com/for_others/gastooon

    is unlocked for easy access to the gooey bits and pieces.

    Works all the way back to IE 5.5, other than the generated content I used in the CSS for the arrows; you could just as easily use background-images or even add span to the markup for sliding doors on those. Just wanted to keep it simple for this demo.

    I'll write up an explanation of it tonight hopefully, on the way out the door right now.
    Java is to JavaScript as Ham is to Hamburger.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles