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>
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;
}
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
Do you know if there is a way to make what i want?
Thank you very much