Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default sort column in rich:datatable

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)

Edit: I wanted it sorted by sn first, uid second.

like image 421
bigGuy Avatar asked May 31 '11 12:05

bigGuy


2 Answers

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.

like image 96
Raimund Avatar answered Oct 22 '22 04:10

Raimund


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"]
}
like image 21
Thor Avatar answered Oct 22 '22 05:10

Thor