cgxp icon indicating copy to clipboard operation
cgxp copied to clipboard

Sort results in FTS

Open rbovard opened this issue 10 years ago • 4 comments

Is it possible to sort FTS results alpha numerically and not just alphabetically?

rbovard avatar Jul 23 '14 08:07 rbovard

Ext automatically sort the values alphabetically, but has no "natural order" sorting, it will require some explicit javascript coding to do that

ochriste avatar Jul 23 '14 08:07 ochriste

Ok thanks for the feedback.

I think the same behaviour should be implemented with the ThemeFinderplugin.

rbovard avatar Sep 03 '14 10:09 rbovard

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;
  });
};

sbrunner avatar Sep 03 '14 12:09 sbrunner

I just saw I've already opened an issue https://github.com/camptocamp/cgxp/issues/782 for the ThemeFinder plugin :)

rbovard avatar Sep 04 '14 06:09 rbovard