What is the best way to define the table default sorting in a browse screen?

Hi

I feel kind of stupid to ask this…

I was expecting to define this in the screens xml definition, but could not find how. My question is related to Cannot declare initial Table sorting by column(s) in XML - CUBA.Platform
I could not open the linked issue in the post - so I do not know the issue status…

My current implementation is this (in the screen controller)

@Subscribe
public void onAfterShow(AfterShowEvent event) {
    singleActorsTable.sort("identifier", Table.SortDirection.ASCENDING);
}

From - Setting a default sorting order for Table - #7 от пользователя kenince.mbithi - CUBA.Platform - I gather I am not totally of…

My questions:

  • Is there a way to define this in xml?
  • If not, is anything wrong with the way I found?

You could do it in the query property of the browse’s collection data container. Right now it will show select e from project_Entity e - change it to select e from project_Entity e order by field1, field2 - obviously change project, entity, field1, field2, etc to match your real world.

1 Like

Hi,
Since 7.2 it’s possible to define sorting in screen XML:
https://doc.cuba-platform.com/manual-7.2/gui_Table.html#gui_Table_column_sort

Thank you both for your answers!

Cheers
Oliver