What is the best way to set a default sort on a datagrid.
On Jmix 1, il was
<column id="MY_COLUMN" sort="DESCENDING"/>
What is the best way to set a default sort on a datagrid.
On Jmix 1, il was
<column id="MY_COLUMN" sort="DESCENDING"/>
Hello,
In Jmix 2, setting a default sort order for a DataGrid is done differently compared to Jmix 1. Instead of specifying the sort order directly in the XML for a column, you should define the sort order in the JPQL query used to load the data. This approach ensures that the data is sorted as desired when it is initially loaded into the DataGrid.
Here’s how you can set a default sort order in Jmix 2:
<data readOnly="true">
<collection id="myEntitiesDc" class="com.company.myapp.entity.MyEntity">
<loader id="myEntitiesDl">
<query>
<![CDATA[select e from MyEntity e order by e.myColumn desc]]>
</query>
</loader>
</collection>
</data>
<layout>
<dataGrid id="myDataGrid" width="100%" dataContainer="myEntitiesDc">
<columns>
<column property="myColumn"/>
<!-- other columns -->
</columns>
</dataGrid>
</layout>
<dataGrid id="myDataGrid" width="100%" dataContainer="myEntitiesDc" multiSort="true">
<columns>
<column property="myColumn"/>
<!-- other columns -->
</columns>
</dataGrid>