Column Sorting on Pivot

How do you sort the columns of a pivot table? I have looked at a number of similar questions, and they suggest using complex objects for the columns array (which just gives me an error) or using the “columnSort” property (which seems to do does absolutely nothing). I’m on v.10.1.5


here’s my structure:

{"rows":["Name"],"fields":[{"name":"Ind Datetime","type":"date"}],"columns":["Ind Datetime_month"],"columnSort": {"$default": {"dir": "desc"},"Ind Datetime_month":{"dir": "desc"}}, "values":[{"name":"Number","operation":"min","id":1695600654070,"color":"#e33fc7"},{"name":"Number","operation":"sum","id":1695600654071,"color":"#a244ea"}],"filters":[],"groupBy":"Ind Datetime_month"}

I need to specify sort orders for each possible field in the dataset, because if the user changes the columns in the configuration, it should still sort properly by the selected field. In my data I have multiple fields for a date: Year, Month, Day, Weekday, so sorting the data on the date does not guarantee each of these fields are sorted. I could also have multiple dates that the user could choose from (e.g. start date, end date, each with their respective multiple fields). Year would be numeric, and so would day, but month and weekday needs to be sorted with the help of a custom function or advanced logic (Jan - Dec, Monday - Sunday).

Hello,

We have already answered this question by email but I will duplicate the answer from my collegue here as well:

You are right, columnSort parameter is no longer available. We will consider adding this functionality in the future, thank you for pointing this out.

For now, in order to sort columns, you can customize the call to the addDimension method and the parameters passed there.

Please check the following example: Code Snippet (line 24).