dataTable sorting date columns

UI Components for Angular
Post Reply
Danieleee
Posts: 22
Joined: 17 Oct 2016, 11:14

07 Dec 2016, 12:43

Hi,
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>
					</template>
				</p-column>
Image

Ashish Burnwal
Posts: 1
Joined: 07 Jun 2019, 07:48

07 Jun 2019, 07:56

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" />
</h:outputText>
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.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests