-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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.