New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cookbook] Add a recipe for sorting in Ember #1305

Closed
wants to merge 5 commits into
base: master
from

Conversation

Projects
None yet
6 participants
@bazzel
Copy link

bazzel commented Feb 17, 2014

I wrote down a HOW-TO on sorting displayed data and I hope this is valid and clear enough so serve as a recipe in the Ember cookbook.

Feel free to adjust, update, re-use or review.

@twokul

This comment has been minimized.

this probably should javascript, not coffeescript

@bazzel

This comment has been minimized.

Copy link

bazzel commented Feb 18, 2014

Sorry about that. CoffeeScript has been replaced.

Please see this [jsFiddle](http://jsfiddle.net/bazzel/wdr7j/) for a working example.

## Solution
Create (or if you already have one: update) a `PostsController` that contains an action that do the actual sorting. This action called is when you click on an element in the template.

This comment has been minimized.

@ugisozols

ugisozols Feb 22, 2014

Contributor

action called is -> action is called


By passing the controller's `sortProperties` and `sortAscending` properties we're able to remember the state and update and look of the element accordingly.

The sorting is done by the controller. The passed property indicated the key the content needs to be sorted on. If the content is already sorted on this property and assume we want to sort in reverse order. Otherwise we sort ascending. Hence the `return false` (since CoffeeScript always the last returned statement) to prevent errors when calling the sort action from a component (see later):

This comment has been minimized.

@ugisozols

ugisozols Feb 22, 2014

Contributor

Code examples were converted to plain JS so comment about CoffeeScript is redundant.

@bazzel bazzel changed the title Add a recipe for sorting in Ember [Cookbook] Add a recipe for sorting in Ember Apr 13, 2014

@wifelette wifelette added the cookbook label Dec 13, 2014

@trek

This comment has been minimized.

Copy link
Member

trek commented Mar 27, 2015

We've migrated to a versioned guides project. Please reopen on https://github.com/emberjs/guides. Thanks!

@trek trek closed this Mar 27, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment