Material-table: How to set type Date output format?

Created on 9 Aug 2019  路  2Comments  路  Source: mbrn/material-table

I need to config output format, to edit some fields defined as type Date.

question

Most helpful comment

I don't know if it is the case, but you can make a custom output using render attribute on the header prop, like this:

  <Table
    headers={[
        { field: 'date', title: 'Date', render: rowData => new Date(rowData.date).toLocaleDateString() }
    ]}
  >

On render, you need to return a function that receives the object in that row, that function need to return a string, or a jsx attribute.

All 2 comments

I don't know if it is the case, but you can make a custom output using render attribute on the header prop, like this:

  <Table
    headers={[
        { field: 'date', title: 'Date', render: rowData => new Date(rowData.date).toLocaleDateString() }
    ]}
  >

On render, you need to return a function that receives the object in that row, that function need to return a string, or a jsx attribute.

I am not sure if this is what you're looking for, but you can specify date, datetime, or time as the type property within columns:

image

This is the code that builds my data:

image

The columns object:

image

Rendered:

image

Was this page helpful?
0 / 5 - 0 ratings