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 5934769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:09:37+00:00 2026-05-22T15:09:37+00:00

How do I change the sort order of a backbone collection after it has

  • 0

How do I change the sort order of a backbone collection after it has already been initialized?

Tried this: Doesn’t work

    collection.comparator = function () {
      // new function
    }
    collectionObject.sort()
  • 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-22T15:09:38+00:00Added an answer on May 22, 2026 at 3:09 pm

    I don’t think you are defining the comparator correctly. If you define a comparator, objects will be inserted into the collection in the right order.

    Here is an example you can just run through firebug on a site with backbone loaded:

    var Chapter  = Backbone.Model;
    var chapters = new Backbone.Collection;
    
    chapters.comparator = function(chapter) { 
      return chapter.get("page");
    };
    
    chapters.add(new Chapter({page: 9, title: "The End"}));
    chapters.add(new Chapter({page: 5, title: "The Middle"}));
    chapters.add(new Chapter({page: 1, title: "The Beginning"}));
    
    chapters.pluck('title');
    
    # OUTPUT
    # ["The Beginning", "The Middle", "The End"]
    

    Notice how the comparator returns the value stored in the page attribute of each chapter. Backbone’s collection sorting acts like a sortBy which uses strings or ints, and doesnt follow a traditional -1,0,1 comparator approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes I have come across this issue that whenever I change the order of
I need to amend a system built in cakePHP to change the sort order
Well, I'd like to know how can I change the sort order of my
How change int value in block, I have this : __block long long size
I need to change the order in which my for-each is executed only if
This is not another question about 'How Can I Sort Dynamically (based on an
How to change default entity order in SonataAdminBundle for list action? answer :) add
I'm using an STL std::multiset<> as a sorted list of pointers. The sort order
Table has surrogate primary key generated from sequence. Unfortunately, this sequence is used for
I already applied a custom order for the toplevel navigation of my page, but

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.