Skip to content
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

Options for ascending/descending sort for ModelList #1004

Closed
rishabhm opened this issue Jul 16, 2013 · 2 comments
Closed

Options for ascending/descending sort for ModelList #1004

rishabhm opened this issue Jul 16, 2013 · 2 comments

Comments

@rishabhm
Copy link

Could an additional attribute be added to the sort() function of a modellist that allows us to specify if we want the list sorted in ascending order or descending? The three functions in question are :

sort -> _sort -> _compare

@ericf
Copy link
Member

ericf commented Jul 16, 2013

The options passed to sort() should be passed along to _sort(); doing so will allow for the following in your code:

var ml = new Y.ModelList();

ml._sort = function (a, b, options) {
    var result = Y.ModelList.prototype.sort.apply(this, arguments);

    if (result === 0) {
        return result;
    }

    return options && options.descending ? -result : result;
};

ml.sort({descending: true});

To make this possible, ModelList needs to be changed so that is passes along the options from sort() to _sort(). Looking at the code, this should be straight forward using Y.rbind().

@ericf
Copy link
Member

ericf commented Jul 23, 2013

Merged #1005, closing…

@ericf ericf closed this as completed Jul 23, 2013
@ghost ghost assigned ericf Jul 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants