Page 1 of 1

dataTable sorting date columns

Posted: 07 Dec 2016, 12:43
by Danieleee
the ordering of the columns that contain the dates do not work.

Code: Select all

<p-column field="datains" header="Data Ins" [style]="{'width':'90px'}" [filter]="true" filterMatchMode="contains" [sortable]="true">
					<template let-data="rowData" pTemplate type="body">
						<span>{{data.datains | date: 'dd/MM/yyyy'}}</span>

Re: dataTable sorting date columns

Posted: 07 Jun 2019, 07:56
by Ashish Burnwal
Two things to follow for the sorting to work properly :)
1) In the form backing bean you need to use Date data type instead of String
2) You will have to use a converter function ex:

Code: Select all

<h:outputText value="#{(<From the backing you are getting the date here>)}">
<f:convertDateTime pattern="dd/MM/yyyy" />
The reason behind this is that, if you use String data type then primefaces sorts the data on the String comparison. So inorder to make primefaces understand that we want to sort on the basis of date , we use a converter function which hints the primefaces and says "Hey primefaces, please use convert the data (which you are getting) to Date format.