1

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>

DataTable Sorting ShowCase

[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.

Community
  • 1
  • 1
09Q71AO534
  • 4,300
  • 13
  • 44
  • 68
  • This can all be found in the PrimeFaces documentation – Kukeltje Apr 06 '15 at 14:02
  • "*If I use `sortMode="multiple"` then I am unable to use `sortBy` and `sortOrder`*". How? The statement is untrue except `sortOrder` is something which is wonky till date - at lease until PrimeFaces 5.1 final (community release). "*I know there is a difference exists between `sort` and `sortMode="multiple"`*". There no such an attribute like `sort`. – Tiny Apr 06 '15 at 17:08
  • possible duplicate of [Initial sortorder for Primeface datatable with multisort](http://stackoverflow.com/questions/15199805/initial-sortorder-for-primeface-datatable-with-multisort) – dognose Apr 07 '15 at 12:08
  • @Tiny Thanks for the comment. I tried the combination of sortBy and sortOrder with sortMode="multiple" which have produced a error. I will check that once again and i will come back. – 09Q71AO534 Apr 07 '15 at 15:19
  • I cannot comment anything about `sortOrder` just because it did not work for me in my attempts and I did not even consider it an issue because it is quite easy to set a default order of our interest anyway. On the other hand, I have been using `sortMode="multiple"` and `sortBy` everywhere since the beginning at several places and found no problem with them except for some ignorance in the library itself in the beginning. – Tiny Apr 07 '15 at 15:27

0 Answers0