Sorting Datatable with empty cells

UI Components for JSF
Post Reply
zlink17
Posts: 1
Joined: 08 Mar 2019, 18:00

08 Mar 2019, 18:26

Hello,

I'm trying to sort a datatable with a column containing empties datas.

Currently, when i do it, i will have empties datas first followed by other datas when it's sorted by descendant. When it's sorted by ascendant, i will get the opposite.

I would like to get empties datas at the end, no matter which king of sorting is used.

I have tried to use a sortFunction to customize the way to sort my table, but it does not work as i expected. When i do so:

Code: Select all

<p:column headerText="Resolution Inco" width="130"
    filterBy="#{inco.dateResolutionInco}"
    filterMatchMode="contains"
    sortBy="#{inco.dateResolutionInco}" sortFunction="#{utilBean.sortByDate}" >
    <h:outputLabel
        value="#{inco.dateResolutionInco}">
    </h:outputLabel>
</p:column>
The function:

Code: Select all

public int sortByDate( Object Date1, Object Date2 )
    {
        LocalDateTime date1 = (LocalDateTime) Date1;
        LocalDateTime date2 = (LocalDateTime) Date2;

        int _res = 0;
        if ( date1 == null && date2 == null )
        {
            System.out.println(
                    "Sort by date: deux null" );
            _res = 0;
        } else if ( date1 == null )
        {
            System.out.println( "Sort by date: date1 null" );
            _res = 1;
        } else if ( date2 == null )
        {
            System.out.println( "Sort by date: date2 null" );
            _res = -1;
        } else
        {
            System.out.println( "Sort by date: none null" );
            _res = date1.compareTo( date2 );
        }
        return _res;
    }
The sortByDate function is called but not for the empties data. So, this is what i get when i have 4 rows with datas and 36 rows without any:

Code: Select all

2019-03-08T17:20:36.068+0100|Infos: Sort by date: aucun null
2019-03-08T17:20:36.068+0100|Infos: Sort by date: aucun null
2019-03-08T17:20:36.068+0100|Infos: Sort by date: aucun null
It seems that the sortFunction is not called when the datas are empties.

Do you know if there is a way to make what i want?

Thank you very much

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

12 Mar 2019, 13:54

the component has an option to tell what you want with null, top or bottom. See the documentation

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 49 guests