Get Free Trial

How to set column sorting for some specific metrics

Denis asked on June 4, 2020

We have a little nasty problem regarding column sorting of some metrics at our grid view.
The fact is that the order of the metrics in the columns is determined by alphabetical sorting. We have a couple of metrics that used as enumeration (for example, 1-2 months, 3-6 months, 6 months – 1 year and etc. and for each of these values there is an identifier (numeric id) that determines the chronological order each of this). And such metrics don’t have the sorting we would like, please, see attaches for details.
So, we want to change the rules for sorting columns for such metrics using id for each value from our enumerations. Can we do this, and if so, by what methods and tools?


1 answer

Illia Yatsyshyn Illia Yatsyshyn Flexmonster June 4, 2020

Thank you for contacting us.
The desired result can be achieved using the sortingMethod API call provided by Flexmonster.
It sets custom sorting for hierarchy members. For more details about defining custom sort, please refer to Custom sorting tutorial.
Please see an example we have prepared for you.
The desired sorting is stored within the sorting object:

let sorting = {
  "3-6 months": 1,
  "6 months - 1 year": 2,
  "1-2 years": 3,
  "2-4 years": 4,
  "4-6 years": 5,
  "6-10 years": 6,
  "10+ years": 7

Next, it is applied using the sortingMethod API call:

pivot.sortingMethod("Tenure", function(a, b) {
  return sorting[a] > sorting[b] ? 1 : -1;

Detailed information about the sortingMethod can be found in our documentation.
Please let us know if it works for your case.
Do not hesitate to contact us in case additional questions appear.

Please login or Register to Submit Answer