I am using Primefaces-3.5 and JSF.
I am fetching a List of Cars
on based on some criteria(Color, Brand and etc.) and a click of a button
and displaying it in a DataTable.
I need to sort a DataTable based on a Column(Car Id)
in the DataTable, so i had used the below code.
<p:dataTable var="car" value="#{dtSortView.cars1}" style="margin-bottom:40px" sortBy="#{car.id}" sortOrder="ascending">
<f:facet name="header">
Sort By a Specified Column
</f:facet>
<p:column headerText="Id" sortBy="#{car.id}">
<h:outputText value="#{car.id}" />
</p:column>
</p:dataTable>
Which sorts the DataTable by default with ascending order of Car Id, but if i change the criteria and then get the list then the DataTable is in descending order of Car Id!.
If i use sortMode="multiple"
then i am unable to use sortBy
and sortOrder
.
I know there is a difference exists between Sort by a specified Column and sortMode="multiple"
, but i want to understand it much more clear way.
Sample Code:
<p:dataTable var="car" value="#{dtSortView.cars1}" style="margin-bottom:40px">
<f:facet name="header">
Single Column Sort
</f:facet>
<p:column headerText="Id" sortBy="#{car.id}">
<h:outputText value="#{car.id}" />
</p:column>
</p:dataTable>
<p:dataTable var="car" value="#{dtSortView.cars2}" sortMode="multiple">
<f:facet name="header">
Multiple Column Sort with Metakey
</f:facet>
<p:column headerText="Id" sortBy="#{car.id}">
<h:outputText value="#{car.id}" />
</p:column>
</p:dataTable>
[Suggested as a Duplicate] (Initial sortorder for Primeface datatable with multisort), but my question much talks about the difference between Sort by a specified column and SortMode
.