StackExchange.DataExplorer
StackExchange.DataExplorer copied to clipboard
Stabilize SlickGrid sorting
The current implementation of client-side sorting (see issue #19) uses the native JS .sort() method, which is not stable in some browsers (such as, notably, Chrome). This can lead to weird behavior when sorting by a column that contains duplicate values, as shown e.g. in this animation.
There's a couple of possible ways to fix this:
- Change the SlickGrid data sorting code to use a custom stable sort method, as suggested in this article.
- Just flat out replace Array.prototype.sort with a stable reimplementation. Here's a suitable drop-in replacement that I've written and added to SOUP.
- Modify the sort comparator callback to use the current order of the rows as a tie breaker if the compared values are equal. This would be the simplest solution if the previous position of the rows is easily accessible in the comparator, which I'm not sure about.
See also: