Reputation: 472
In the example here http://knockoutjs.com/examples/betterList.html, when I add "trees" and "bees" then click sort, it sorts the original items in the observable array separately from the two new items. How do we fix this, or is it a known bug?
Update: based on mckeejm's answer, to do a case insensitive sort, replace
this.sortItems = function() {
this.allItems.sort();
};
with
this.sortItems = function() {
this.allItems.sort(this.sortFunction);
};
// refer to http://stackoverflow.com/questions/6965951/sorting-an-observablearray-for-one-of-the-templates
// and http://jsfiddle.net/rniemeyer/93Z8N/
this.sortFunction = function(a, b) {
return a.toLowerCase() > b.toLowerCase() ? 1 : -1;
};
Upvotes: 1
Views: 128
Reputation: 2882
This is not a bug, this is ASCII-based sorting. The ASCII code for upper case characters starts at 65, and lower case starts at 97. Try, "Bees" and "Trees" and you'll see the difference.
Upvotes: 2