Reputation: 249
I would like to specify a default sorting column of a tapestry grid.
I understand that I could sort the records in my getter on the server side, however this seems like unnecessary effort, since grid is perfectly capable of sorting on it's own.
So my grid definition looks like:
<t:grid source="queues" inPlace="true"> </t:grid>
The getQueues returns collection of objects like:
public class Queue {
public String getName();
public float getOccupancy();
}
I would like to make the grid sorted by 'occupancy' attribute in descendent order by default.
From the Tapestry documentation I see, that Grid has attribute sortModel which seems like the right option. However I can't find good explanation of what are the right values to set it to.
Upvotes: 5
Views: 1996
Reputation: 27994
You could probably write a mixin to set the initial sort
@MixinAfter
public class DefaultSort {
public enum Order { ASCENDING, DESCENDING };
@Parameter(required=true, defaultPrefix="literal")
private String sort;
@Parameter(defaultPrefix="literal", value="literal:ascending")
private Order order;
@InjectContainer
private Grid grid;
@SetupRender
void setupRender() {
GridSortModel sortModel = grid.getSortModel();
if (sortModel.getSortConstraints().isEmpty()) {
sortModel.updateSort(sort);
if (order == Order.DESCENDING) {
// updateSort a second time for DESCENDING
sortModel.updateSort(sort);
}
}
}
}
<t:grid source="queues" inPlace="true" t:mixins="defaultsort" sort="occupancy" />
Upvotes: 6