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:
image

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?

Hi,

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

@UiController("pivot-table-sorter-function")
@UiDescriptor("pivot-table-sorter-function.xml")
@LoadDataBeforeShow
public class PivotTableSorterFunctionSample extends ScreenFragment {
    @Inject
    private PivotTable pivotTable;
    @Inject
    private MessageBundle messageBundle;

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

messages.properties

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

Take a look at this online demo.

Gleb

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?