Cannot declare initial Table sorting by column(s) in XML

Related to: https://www.cuba-platform.com/discuss/t/cannot-get-the-current-sorting-applied-to-a-table-component

Even if the above issue has been solved, I cannot find a way to declare the initial sorting of the table, if my collectionDatasource is initially ordered.

EDIT: This problem becomes more severe when applied to nested datasources… In that case it is impossible to define the initial sorting declaratively in XML (you need to apply the sort by writing code in the controller, but for this simple need should be avoided).

Sample scenario:

declare a collectionDatasource like


<collectionDatasource id="sectionsDs"
                      class="it.nexbit.webschool.entity.Section"
                      view="section-browse-view">
    <query>
        select s from webschool$Section s order by s.label
    </query>
</collectionDatasource>

then declare a table


<table id="sectionsTable"
       presentations="true"
       width="100%">
    <columns>
        <column id="label" <i>&#91;&#91; HERE I'd like an attribute such as initialSortPriority="0" that tells this field should be ordered by default on first opening AND it is the first one of many &#93;&#93;</i>/>
        <column id="grades"/>
    </columns>
    <rows datasource="sectionsDs"/>
</table>

in this case there is no visual clue for the user that the table is indeed ordered by label…

IMHO it is best to avoid the order by clause altogether, and instead add an attribute to the column that triggers the orderby on initial screen opening.
When the user overrides the default ordering, that attribute would be ignored.

Actually, to specify multiple columns, the attribute could be an integer one, that indicates the sort priority, and there should be another attribute for the order (ASC or DESC).

So for example:


<column id="label" initialSortPriority="0" initialSortOrder="desc"/>

Thanks
Paolo

Hi,

Thank you for the idea, we will take a look how to implement this!

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-9803