Page 1 of 1

dataTable sort issues with sortBy and filterBy columns

Posted: 23 Nov 2010, 09:32
by MarkB
Hi

I am experiencing some peculiarities with sorting columns in a p:dataTable component. I'm wondering if I have coded this incorrectly or whether this is a 2.2.RC2 issue still being resolved.

I have a dataTable (and first column) defined thus:

Code: Select all

            <p:dataTable id="RecTbl"
                         binding="#{countryGridBean.grid}"
                         rows="#{countryGridBean.filterGridRows}"
                         paginator="true"
                         paginatorAlwaysVisible="false"
                         paginatorPosition="both"
                         pageLinks="4"
                         paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                         dynamic="true" 
                         value="#{countryGridBean.recs}" var="txn">

                <!-- country code -->
                <p:column rendered="#{countryGridBean.colCode}"
                          sortBy="#{txn.ctryCode}">
                    <f:facet name="header">
                        <h:outputText value="Code"/>
                    </f:facet>
                    <h:outputText value="#{txn.ctryCode}"/>
                </p:column>
<!-- other columns-->
The table shows the sort indicator within the column heading. When I click on the header the sort indicator changes to show ascending sort. When I click again the sort indicator changes to show descending sort sequence. However the data rows within the table remain unchanged.

If I add a filterBy attribute to the column as:

Code: Select all

                <p:column rendered="#{countryGridBean.colCode}"
                          sortBy="#{txn.ctryCode}" filterBy="#{txn.ctryCode}">
then clicking the column header shows the same behaviour. However if I enter something into the filter field for the column then the data rows change to match the filter. The sort feature now works for the column (and all other sortable columns). If I now clear the filter field to show the full original set of row data - the sort feature continues to work.

I've only been using Primefaces for a week, converting some existing code to use the components, so I could easily be missing something critical in the code. I would appreciate knowing what I have coded incorrectly or whether this is a 2.2.RC2 issue still being resolved and therefore I will just wait before implementing sorting.

Thank you for your help.

Re: dataTable sort issues with sortBy and filterBy columns

Posted: 24 Nov 2010, 10:54
by vdweij
I can confirm this exact behaviour. Sorting does only work once column filtering has been used

PrimeFaces 2.2
JSF Mojarra 2.1.0 (FCS b07)
jetty-8.0.0.M1

This topic is probably related to this one:
http://primefaces.prime.com.tr/forum/vi ... f=3&t=5433

Re: dataTable sort issues with sortBy and filterBy [Solved]

Posted: 07 Dec 2010, 08:06
by MarkB
The issue was mine!

In my backing bean the list of items passed to the dataTable was of type ListDataModel<T> since that was the required for the original code. When I changed this to type List<T> then the column sort worked as expected.