How to sort Date/Time column in angular 4 material sort?

前端 未结 5 598
借酒劲吻你
借酒劲吻你 2021-02-13 21:08

I\'m using angular material table and using matSort for sorting. But it\'s not sorting the dates/time column. It takes the datetime column values as strings.

How to sor

5条回答
  •  感动是毒
    2021-02-13 21:45

    In addition to the Sagar Kharche's post, if your date is from firebase, I recommended you to do this:

    this.dataSource.sortingDataAccessor = (item, property) => {
        console.log(item)
        switch (property) {
          case 'fromDate': {
            return new Date(item.fromDate.seconds * 1000);
          }
          default: return item[property];
        }
      };
    

提交回复
热议问题