0

Problem with sorting date. Sorting works by hours not by all date: console.log

    1. apr. 2022 16.54.32
    1. jan. 2022 12.57.16
    1. aug. 2022 10.52.22
    1. apr. 2022 16.54.32
 announceSortChange(sortState: Sort) {

        this.dataSource.sortingDataAccessor = (item, property) => {
          console.log(item.timeStamp)
          switch (property) {
    
            case 'time':
               return item.time;
              break;
       
            default:
              return item[property];
          }
        };
       
      
        ///this code from table whre table is:
    
      getColumns() {
        return [
          {
            key: 'time',
            getValue: element => element.time,
            title: $localize`:|Column:Date`,
          }}
    
    export interface Task {   id: number;   time: string; }

table is reusable and self-adjusts to the data

I put something like that: 
     return item.time = new Date(item[property]).getTime();
 and when I press sort In table I have: NaN

1 Answers1

0

This might help you:

Angular 6 Sort Array of object by Date

https://bobbyhadz.com/blog/typescript-sort-array-of-objects-by-date

I suggest making Date Objects or ISO Strings and comparing them. You can also use Libraries like MomentJS

Unknown
  • 83
  • 1
  • 9