How to sort an enum by the values

Hi, I’m trying to make an budget pivot table, and I’ve created an enum for the months. The image below shows what I did:

The months are ordered by alphabetical order, and I want to order it by the values (they are defined as integer in the enum class, and the values are ordered, ex.: JANEIRO(1), FEVEREIRO(2), MARCO(3), …). So, how can I do what I want?


You need to define sortersFunction - a JavaScript function that will be used for rows and columns captions sorting, e.g.:

public class PivotTableSorterFunctionSample extends ScreenFragment {
    private PivotTable pivotTable;
    private MessageBundle messageBundle;

    protected void onInit(InitEvent event) {
        pivotTable.setSortersFunction(new JsFunction(messageBundle.getMessage("function.sorters.dayOfWeek")));

function.sorters.dayOfWeek = function(attr){\
        return $.pivotUtilities.sortAs(["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]);\

Take a look at this online demo.


Hi, thanks for your answer. But I would like to sort the enum because I’m also using this enum in a lookup field. There is a way to do it? Or other way that I can use to order it in the lookup field?

LookupField automatically considers enum values order. Do you have another order?