Format Date in p-dataTable

UI Components for Angular
Post Reply
tomwalls
Posts: 4
Joined: 27 May 2016, 23:33

16 Jun 2016, 18:54

Hi All

Im trying to format a date of 2016-06-11T16:20:00.0000000 to 2016-06-11 16:20

Below is the code in my HTML inside a p-column field

<p-column field="date | date : 'dd/MM/yy HH:mm:ss'" header="Date" [sortable]="true"></p-column>

Has anyone any guidance on this?

Thanks

clutz
Posts: 1
Joined: 22 Apr 2016, 21:18

17 Jun 2016, 22:08

Tom,

A <p-column> is not angular expression, so pipes and filters do not affect the values you put in there. The field expression is a string value that p-column will use to look up (i.e.: hash table reference) from the context of the column. To do what you're looking for you need to use a content template for the p-column.

Code: Select all

        <p-column field="date" header="Date" [sortable]="true">
            <template let-col let-data="rowData">
                <span>{{data.date | date: 'dd/MM/yy HH:mm:ss'}}</span>
            </template>
        </p-column>
Please note you'll need Angular2 updated to RC2 to make the date formatting work the way you want.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

18 Jun 2016, 14:22

+1 for pipes

techravindra
Posts: 1
Joined: 13 Jul 2017, 12:26

13 Jul 2017, 12:32

Hi,

I am trying to format decimal number using the same approach suggested by you, but it is not working. Please help.

<p-datatable [value]="positions"
<p-column field="amount" header="Date" [sortable]="true">
<template let-col let-data="rowData">
<span>{{ data.amount| number: '3.2-5'}}</span>
</template>
</p-column>
</p-datatable>

vts
Posts: 1
Joined: 12 Feb 2018, 15:36

12 Feb 2018, 15:46

Hi,

I would like to dynamically display set of columns. Is there any standard way to dynamically apply pipes/formater in this case:
<p-column *ngFor="let col of columns" [field]="col.field" [header]="col.header" sortable="true"></p-column>

Thanks!

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 27 guests