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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:25:18+00:00 2026-06-07T06:25:18+00:00

I have a Ember.ArrayController that has an unsorted content. I want to know if

  • 0

I have a Ember.ArrayController that has an unsorted content.

I want to know if its possible to sort the content of an ArrayController without using a new property.

I could of course create a new property:

App.MyArrayController = Em.ArrayController.extend({
  mySortMethod: function(obj1, obj2) {
    // some code here
  },
  updateSortedContent: function() {
    var content = this.get('content');
    if (content) {
      var sortedContent = content.copy();
      sortedContent.sort(this.mySortMethod);
      this.set('sortedContent', sortedContent);
    }
  }.observes('content')
});

But I hope there is a better way that does not duplicates the content.

  • 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-06-07T06:25:19+00:00Added an answer on June 7, 2026 at 6:25 am

    UPDATE

    The latest version of Ember actually has sorting built in. ArrayController now includes the Ember.SortableMixin which will engage if you specify sortProperties (Array) and optionally sortAscending (Boolean).

    Note: with the new SortableMixin, you still need to refer to arrangedContent to get the sorted version. The model itself will be left untouched. (Thanks to Jonathan Tran)

    App.userController = Ember.ArrayController.create({
      content: [],
      sortProperties: ['age'],
      sortAscending: false
    })
    

    ORIGINAL ANSWER

    The correct way to do this is to use the arrangedContent property of ArrayProxy. This property is designed to be overridden to provide a sorted or filtered version of the content array.

    App.userController = Ember.ArrayController.create({
      content: [],
      sort: "desc",
      arrangedContent: Ember.computed("content", function() {
        var content, sortedContent;
        content = this.get("content");
        if (content) {
          if (this.get("sort") === "desc") {
            this.set("sort", "asc");
            sortedContent = content.sort(function(a, b) {
              return a.get("age") - b.get("age");
            });
          } else {
            this.set("sort", "desc");
            sortedContent = content.sort(function(a, b) {
              return b.get("age") - a.get("age");
            });
          }
          return sortedContent;
        } else {
          return null;
        }
      }).cacheable()
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Ember.js app that has a Checklist model, where each Checklist has
I have a simple property on an Ember object that I want to run
It is possible to have whitespace in an Ember.Object 's field name, but how
I am new to Ember.js. I have the following experiment in my HTML: <p>Username:
For this example, I have a dictionary, that when I call on it, Ember
I am using Ember.js to create a table from a json feed. I have
I have the following ember controller that is going to wait for json objects
I have an Ember.js model that's basically just an ID, a title, a body,
I have a basic Ember application. It has 2 controls: a select element and
I have an ArrayController which is periodically updated. It has a sorted computed property

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.