Sorting an enyo.Collection

Any recommendations? Seems like something that should be core but I didn't see anything to support it.


  • We don't have anything implemented for this at the moment, but we know it is a need.

    I feel like a design for this would also tie in nicely to the wish to group related records together for things like list dividers.

    Backbone uses the idea of a collection comparator, a property that defines a sort method or specified an attribute to use. I could see taking this one further and having the ability for a sort method to also return a "group" identifier, like the first letter or some other data that would group like records together.
  • edited November 2013
    having the ability for a sort method to also return a "group" identifier
    that's sounds like a good idea
  • edited November 2013
    This is only useful in specific circumstances, not a core requirement. Sorting itself can be highly specific depending on the data. There is an extensible filtering API already available that can be used for this purpose.

    Edit: I'm not against adding an API exclusively for sorting, but there would be a lot of overlap between that and the filtering API that can be used for essentially the same thing. But the specificity of the feature @unwiredben mentioned would be an implementation choice possible by such an API, but not the default.
  • I got confused looking at the enyo.Collection implementation because filter is overloaded. There's both the concept of filter methods which return arbitrary arrays of data and the separate filter() method which is used to run a yes/no function over the collection, producing a new array of results. So, you can use the activeFilter concept to pick a sort function or any sort of model transformation you want.
  • while I can see how the filter API could be used for sorting, that's not particularly intuitive. i'll dig into it a bit and see where it takes me.
  • Sharing my current work on this problem. This version is built as a mixin and uses the existing enyo.Collection filter API. I still think a separate API for sorting would be appropriate (e.g. what if i wanted to filter the contents and sort them? I'd have to build sorting into my filtering which seems unnecessary.).
  • Revised the code to work independently of the filter API though it still ties into filtering to apply the sort correctly.
  • This is no longer possible, right? clearFilter and activeFilter are gone in Enyo 2.4.

    Is there any way to sort the records inside a collection and still use Enyo's data binding?
    I could not figure out how to do this. I tried to sort an array an then add it to a collection, but output order seems to be random.
  • My mistake. The order will be preserved if you add an array with all sorted records. I do not know what happens if you add/merge some more.
Sign In or Register to comment.