There is a particular issue that is really frustrating me in one of my projects.
The code I have is quite similar to this example (I tried to replicate it as closely as possible, but the actual code doesn't seem to be relevant because I can't reproduce the issue there anyway): http://plnkr.co/edit/SCUCsxLgu2zFzMhZ0whs?p=preview
The problem arises when I set predicate=''
- the sorting doesn't completely clear. Angular seems to rearrange my elements in a different order (as seen in this screenshot with predicate=''
):
When I removed the orderBy
, everything displayed in the correct order (similar to how it was retrieved from the repository). Despite numerous attempts with orderBy
, I couldn't fully reset the sorting.
I came across a similar case here: AngularJS ngRepeat orderBy in Chrome, but it turns out that my situation is not related to that specific issue.
Being patient, I delved into the angular.js
file (AngularJS v1.3.15) for debugging purposes. The critical line appears to be:
return slice.call(array).sort(reverseComparator(comparator, reverseOrder));
Before slice.call(array)
, the array maintains its order. However, the result gets jumbled up after executing the sort
function. This prompted me to do the following:
function comparator(o1, o2) {
for (var i = 0; i < sortPredicate.length; i++) {
var comp = sortPredicate[i](o1, o2);
if (comp !== 0){
console.log(7); // <---------------------
return comp;
}
}
console.log(0); // <---------------------
return 0;
}
function reverseComparator(comp, descending) {
return descending
? function(a, b) {return comp(b,a);}
: comp;
}
To my surprise, on setting predicate=''
, my console outputs only zeros.
Additionally, running:
slice.call(array).sort
...yields:
function sort() { [native code] }
So, the reason behind this unexpected sorting remains unknown to me. Interestingly, this issue only occurs in Chromium-based browsers (tested on Chrome and Opera). FireFox and IE11 clear the sorting as expected.
Initially, I considered this to be a bug in Chromium, yet I haven't been able to replicate it in the Plnkr setup. I'm left wondering if there's something different about the data that could be causing this discrepancy...
I even tried disabling all my Chrome extensions, but it had no impact on the issue either.
Given the popularity of both Chromium and Angular, has anyone else encountered this anomaly before?
Any insights or suggestions on what might be causing this issue would be greatly appreciated!
UPDATE:
Finally, I believe I've managed to reproduce the problem by adding more items to my array. Check it out here: http://plnkr.co/edit/SCUCsxLgu2zFzMhZ0whs?p=preview
(celebration time! :D)
I plan to report this to the Angular team in hopes that they, being Google, might address and resolve this issue with Chromium as well. :D