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
  • technical details which provided is not suffice to answer. Commented Nov 25, 2022 at 9:15

1 Answer 1

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

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.