Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(filter): orderBy for object collections #6337

Closed
wants to merge 1 commit into from

Conversation

khepin
Copy link

@khepin khepin commented Feb 19, 2014

Allows to use orderBy filter on collection objects and not only arrays.

eg:

var c = {
    b: {name: 'b'},
    c: {name: 'c'},
    a: {name: 'a'}
};
orderBy(c, 'name'); // => [{name: 'a'}, {name: 'b'}, {name: 'c'}];

Closes: #6210

Allows to use orderBy filter on collection objects and not only arrays.

Closes: angular#6210
@khepin khepin added cla: no and removed cla: yes labels Feb 19, 2014
@khepin
Copy link
Author

khepin commented Feb 20, 2014

CLA should be ok now hopefully.

@mary-poppins
Copy link

CLA signature verified! Thank you!

Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes).

if(isObject(sortable)) {
array = [];
for (var key in sortable) {
if (sortable.hasOwnProperty(key) && key.charAt(0) != '$') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like that we're losing object keys with this, I dunno. It basically transforms the object into an array, and it's impossible to sort by the key of the object (which would be a cool trick, even for arrays)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but hmm, maybe it doesn't matter that much.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point about that but to keep the key, we would have to return a different structure like [{key: 'userName', value: {/* an object*/}}, ...] which is an even worse solution I believe. If the keys are important though, and maybe even sorting the keys, I think the best way is to first create an array of the keys then iterate on the keys.

@btford btford added this to the Backlog milestone Mar 17, 2014
@nodecode
Copy link

nodecode commented Aug 1, 2014

If support for objects released soon?

@petebacondarwin
Copy link
Contributor

I have created a module that provides the toArray filter for helping with these situations

http://ngmodules.org/modules/angular-toArrayFilter

@Narretz
Copy link
Contributor

Narretz commented Jun 9, 2015

I think we can close this, based on #11255

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngRepeat iterates over object in alphabetical order
9 participants