cgxp
cgxp copied to clipboard
Sort results in FTS
Is it possible to sort FTS results alpha numerically and not just alphabetically?
Ext automatically sort the values alphabetically, but has no "natural order" sorting, it will require some explicit javascript coding to do that
Ok thanks for the feedback.
I think the same behaviour should be implemented with the ThemeFinder
plugin.
We can make something like:
https://blog.jcoglan.com/2008/01/04/natural-order-sort-in-javascript/
Array.prototype.naturalSort = function() {
var p, q, valueOf = function(t) {
return isNaN(t) ? t.charCodeAt(0) :
Number(t) - Math.pow(2,32);
};
return this.sort(function(a,b) {
var values = [a,b].map(function(s) {
return s.toString().toLowerCase()
.match(/([a-z]|[0-9]+(?:\.[0-9]+)?)/ig);
});
a = values[0]; b = values[1];
for (var i = 0, n = Math.min(a.length, b.length); i < n; i++) {
p = valueOf(a[i]), q = valueOf(b[i]);
if (p != q) return p - q;
}
return a.length - b.length;
});
};
I just saw I've already opened an issue https://github.com/camptocamp/cgxp/issues/782 for the ThemeFinder
plugin :)