问题
I have rich:dataTable with multiple sortable columns.
<rich:column sortBy="#{user.uid}">
...
<rich:column sortBy="#{user.sn}">
...
etc.
Sorting works fine. However, when page is loaded, table is always sorted by 1st column. How can I set "default" sorting column? (for example, the one with user.sn)
回答1:
I suppose you will have to sort the underlying list. By default the table will be ordered like the list is that you pass as value.
回答2:
The sort order of a column is defined by its sortOrder property: NONE, ASCENDING or DESCENDING.
Per default this property is NONE - so initially the table isn't sorted on any column (nor the first). It uses the ordering of the data model.
To define an initial sort column, set the sortOrder of this column, e. g.
<rich:column sortBy="#{user.sn}" sortOrder="ASCENDING">
This is true for rich:dataTable, rich:scrollableDataTable and rich:extendedDataTable as well.
回答3:
I'm not sure how to do this with a rich:dataTable
. But I have in mind, that I switched for a similar feature request (individual ordering and sorting of tables) to rich:extendedDataTable
. There you can create a binding to tableState and set e.g. this properties:
{
"columnsVisibility":{"cCountry":"1","cProject":"1","cStatus":"1","cNumber":"1"},
"columnGroupingState":{"order":"ASCENDING","columnId":"cStatus"},
"columnsSizeState":{"cCountry":"98","cProject":"242","cStatus":"80","cNumber":"55"},
"columnsOrder":["cCountry","cProject","cNumber","cStatus"]
}
来源:https://stackoverflow.com/questions/6187748/default-sort-column-in-richdatatable