0

I have a table using Primeng for displaying the table values. In the table there is one column for date, for date the sort option is not working. It is considering as normal string value instead of Date.

From the service getting the date in timestamp format. Using below code in UI to convert the date in required format.

import { DatePipe } from '@angular/common';
constructor(private datePipe: DatePipe) {
}



dateFormat(val: any) {
    if (val.toString().indexOf('.') > 0) {
      return this.datePipe.transform(new Date(val * 1000), 'd-MMM-y');
    } else {
      val = val.toString() + '.0000';
      return this.datePipe.transform(new Date(val * 1000), 'd-MMM-y');
    }
  }
Shiny
  • 127
  • 1
  • 6
  • 12

2 Answers2

0

You can set one field for display date

this.data.forEach(ds => {
      ds.display_year = this.dateFormat(ds.year);
});

But sort on real field (date type)

This is demo

phucnh
  • 1,020
  • 6
  • 14
0

have you tried using datepipe in 's column: {{your_date | date: 'dd/MM/yyyy'}}

Mayur Saner
  • 444
  • 5
  • 10