Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Format date in Datatable dataset

GrantPhillips priority asked 3 years ago


We have data that is returned from an API and it contains numerous date fields. When the dates are displayed in the MDBDatatable, they are output in the following format:Tue Oct 05 2021 09:42:13 GMT+1300 (New Zealand Daylight Time)

We would like to display the dates with a format of "dd-MM-yyyy".

We would like to use the Column 'format' attribute to be able to change the display value


Mikołaj Smoleński staff commented 3 years ago

I recommend to use e.g. dayjs package for parsing date objects and make inside the fetch method (or axios if you use this library). It's described here: https://mdbootstrap.com/docs/b5/vue/data/datatables/#section-async-data.

An example of data managing is here:

        .then(data => {
          dataset9.value.rows = data.map(user => ({
            ...user,
            address: `${user.address.city}, ${user.address.street}`,
            company: user.company.name
          }));
          loading9.value = false;
        });

Keep coding, Mikołaj from MDB



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Resolved

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB Vue
  • MDB Version: MDB5 1.4.0
  • Device: PC
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: No
  • Provided link: No