Tables within a web application created with X4 Web Apps can be sorted by the values within a column.
In the example already used for Paging, some changes are made to be able to sort. First, the column in the List component must be marked as sortable (sortable="true").
<ListComponent name="Sorting" path="Sorting" displayName="Paging" process="fillListProcess.wrf" default="true">
<Properties>
<Property name="List" type="Complex">
<Property name="Description" type="String" displayName="Description"/>
<Property name="Id" type="Integer" displayName="Id"/>
</Property>
</Properties>
<Columns>
<Column value="#List.Id" sortable="true" />
<Column value="#List.Description" />
</Columns>
</ListComponent>
The column header now looks like this:
The sort icon shows that sorting is enabled for this column. Note that the sortable="true" property only displays the sort icon in the column header. It does not sort the data. The sorting itself has to be implemented at application level.
When sorting is enabled, the process that loads the data receives the sort criterion the user selected as input. This includes the property the sort applies to. Two examples:
Ascending order:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Search offset="0" limit="50">
<OrderBy>
<Asc property="#List.Id" />
</OrderBy>
<Where />
</Search>
Descending order:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Search offset="0" limit="50">
<OrderBy>
<Desc property="#List.Id" />
</OrderBy>
<Where />
</Search>
The list-loading process has to read the <OrderBy> element and apply the requested sort direction (<Asc>/<Desc>) to the given property (property attribute) when it gets the data.