-1

I am using PrimeNG Data table, table has multiple columns, one of them is date column with date format like 'DD MMM YYYY, hh:mm' How can I sort by date a column without changing date format? I assume it sorts by its string value because it doesn't sort correctly,

Is there any workaround or fix for this issue?

Thanks

R. Richards
  • 24,603
  • 10
  • 64
  • 64
arvind
  • 1
  • 3

1 Answers1

1

I'm not sure about PrimeNG but I think that you can have two properties date and dateToSort (dateToSort is the date in format YYYYMMDD and indicate that the column to order is dateToSort

<ng-template pTemplate="header" let-columns>
  <tr>
    <th *ngFor="let col of columns" 
        [pSortableColumn]="col.field=="date"?"datesort":col.field">
                {{col.header}}
        <p-sortIcon [field]="col.field"></p-sortIcon>
    </th>
  </tr>
</ng-template>

Some looks like in this SO about material table

Alex Choroshin
  • 6,177
  • 2
  • 28
  • 36
Eliseo
  • 50,109
  • 4
  • 29
  • 67