0

My JSF code goes like this:

<p:dataTable var="result" value="#{timerConfigurationJobList.model}" rows="10"
                         paginator="true" paginatorPosition="bottom"
                         paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                         rowsPerPageTemplate="10,20,50" id="approvalTable" lazy="true">           
                <p:column sortBy="#{result.jobId}">
                    <f:facet name="header">
                        <h:outputText value="#{msg['content.jobList.jobId']}"/>
                    </f:facet>
                </p:column >
 </p:dataTable>

The result I get is this :

'Wrongly sorted'

As can be seen in the picture: '123' is higher than '2', '4', '7' and '9'. I want it to come right at the end, so that it is 'numerically' sorted.

Am using Java and JSF 2.

Edit: In the lazy model I found this:

@Override
    public final List<T> load(int first, int pageSize, String sortField, SortOrder sortOrder,
            final Map<String, Object> filters) {

        Map<String, Sort> sorts = new HashMap<>();

        if (sortField != null) {
            if (sortOrder.equals(SortOrder.ASCENDING)) {
                sorts.put(sortField, Sort.ASC);
            } else if (sortOrder.equals(SortOrder.DESCENDING)) {
                sorts.put(sortField, Sort.DESC);
            }
            // unsorted can be ignored
        }
ITguy
  • 847
  • 2
  • 10
  • 25

1 Answers1

0

There are multiple ways to solve the issue:

  1. Change the type of column as mentioned by @Kukeltje. Not sure whether you want to change the schema.
  2. Use sortFunction attribute of column to provide the custom sorting.
  3. Pass the sorted list of JSF component.
Sumit Gulati
  • 665
  • 4
  • 14