Displaying date in DataTable problem

UI Components for Angular
Post Reply
SuperSerb
Posts: 8
Joined: 03 Aug 2016, 11:15

03 Aug 2016, 11:22

Hello everyone, I have the following problem:

I am instantiating DataTable columns dynamically using an array which I am iterating with ngFor like this:

Array

Code: Select all

this.cols = [
            { field: 'id', header: 'ID' },
            { field: 'name', header: 'Name' },
            { field: 'date', header: 'Date' }
        ];
DataTable with ngFor iteration

Code: Select all

<p-dataTable [value]="users" class="table">
    <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header"></p-column>
</p-dataTable>
And it is working, but I can't find a way to format miliseconds to date, for example 1470211189830.
I saw these two solutions:

http://forum.primefaces.org/viewtopic.php?f=35&t=45955
http://forum.primefaces.org/viewtopic.php?f=35&t=45677

But, I want to keep instantiating DataTable columns dynamically, so this solution doesn't help me.
Thanks in advance.

JiroDan
Posts: 20
Joined: 14 Jul 2016, 22:07

03 Aug 2016, 19:05

Have you tried adapting the template with the pipe solution and adding an if expression?

If the data in the column fits some date range (long value between 946684800000 and 1735689600000 -- which is 1/1/2000 - 1/1/2025)?

something like:
<template let-col let-data="rowData">
<span>{{!isNaN(data)?(data >= 946684800000 && data <= 1735689600000 ? data | date: 'dd/MM/yy HH:mm:ss':data):data}}</span>
</template>

(have not tried this, just a suggestion)

SuperSerb
Posts: 8
Joined: 03 Aug 2016, 11:15

04 Aug 2016, 09:05

That doesn't really work for me because later I may have long values that are not dates.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests