Topic: MDBDataTableV5 display date object in different format

ClassBook free asked 2 years ago


I would to Input Date Object into MDBDataTableV5, and display in different format for example dd/mm/yyyy. The reason why I want Date object instead of String is because when I sort by the Date field, the sorting is incorrect for the String formatted field.

May I know whether this feature is available or is there an alternative way to resolve the problem?


Wojciech Staniszewski staff commented 2 years ago

We had already planned to create such a feature, but firstly it needs to be added at MDB Standard. For now, you just have to display data in a specific format.


ClassBook free commented 2 years ago

@Wojciech Staniszewski May I know is there any eta for the implementation?


Wojciech Staniszewski staff commented 2 years ago

We will add this feature in the next release


frankvdsm priority answered 2 years ago


Hi,

Don't apply the format to your datatable but create a function like this:

public showTimestamp(n: string) {

let y = n.substr(0,4);
let m = n.substr(5,2);
let d = n.substr(8, 2);
return d + "/" + m + "/" + y;

}

in your HTML us this function like this:

<tr *ngFor="let v of table.data" scope="row">
  <td>
    {{ showTimestamp(v.datum) }}
  </td>

Your data is always shown in the right format and is also shown sorted correctly.

Regards, Frank



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: MDB5 1.3.0
  • Device: NA
  • Browser: NA
  • OS: NA
  • Provided sample code: No
  • Provided link: No