Displaying date in DataTable problem

UI Components for Angular
Post Reply
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:


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>
And it is working, but I can't find a way to format miliseconds to date, for example 1470211189830.
I saw these two solutions:


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

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>

(have not tried this, just a suggestion)

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 6 guests