Reputation: 2963
I create 3 group - priorty 1,2 and 3 and use orderBy:priorty expect each pushed task will goes into their group. But after I test with more data I found within each group there's strange behaviour, which they don't sort properly.
<input ng-model="taskName"/>
<button ng-click="AddTask()">Push task</button>
<li ng-repeat="task in tasks | orderBy:'priorty'">priorty {{task.priorty}} - {{task.taskName}}</li>
newly items got pushed not to the bottom but sometime to the top / middle, why is this happens?
try my demo : http://plnkr.co/edit/V5aIZcLbhiSfLy1vEWoe?p=preview
Upvotes: 0
Views: 87
Reputation: 48211
The items are always in correct order according to priority
.
Other than that there is no requirement (and no guarantee) regarding the order of items within the same priority.
If want to have a second level of ordering, you can pass a list of properties to the orderBy
filter:
ng-repeat="task in tasks | orderBy:['priorty','taksName']"
See, also, this short demo.
Regarding the "why" of your question
(why does the re-ordering take place if you only order by 'priority'):
It seems to be browser-specific. The same code on Firefox does not "reorder" the items after inserting the 9th item (as does Chrome).
If I were to take a guess, I'd say it has to do with the way each browser keeps some reference to elements (internally) and at which point they decide to do some rehashing.
Upvotes: 1