Reputation: 727
I have a bookDatasource. One book has many authors. The collection is displayed in a grid on the book-edit-view. Now I want to sort by authors name. In the collectionDatasource properties I set sortable to true. How can I do it?
Upvotes: 1
Views: 849
Reputation: 86
If I understand correctly, you're binding Table and Book Authors using nested datasource, like that:
<datasource id="bookDs"
class="com.company.test.entity.Book"
view="book-edit-view">
<collectionDatasource id="authorsDs" property="authors"/>
</datasource>
If so, first, ensure that Book entity has collection of Authors attribute of ordered type (List or LinkedHashSet). If its not you can change collection type in Studio or manually in Book entity.
Then table column becomes sortable - when user clicks on column header table will sort rows accordingly. Also CUBA Platform will handle saving sorting setting as user settings - so next time user opens the screen table will be sorted.
In order to enable sorting of Book Authors by default you could do it on ORM level. In Studio open entity Book, click on authors attribute and set value name in Order by field in attribute properties panel. This will ensure that any instance of Book entity has authors sorted by name.
Upvotes: 7