Search code examples
momentjsreact-bootstrap-table

How to use the moment library in React Bootstrap table's column definition?


My code looks as following:

const columns = [{
  dataField: 'Id',
  text: 'Order ID'
}, {
  dataField: 'Date',
  text: 'Date'
}, {
  dataField: 'Total',
  text: 'Total'
}];

And it displays date in React Bootstrap table. But, the date is in Json format that I don't need.

I've tried to use the moment library to format date in this way:

const columns = [{
  dataField: 'Id',
  text: 'Order ID'
}, {
  dataField: '{moment(Date).format("DD-MM-YYYY")}',
  text: 'Date'
}, {
  dataField: 'Total',
  text: 'Total'
}];

But, the date column is empty.

How can I use the moment library to format the dates for columns in React Bootstrap table's library? Or there is some another way to do it?


Solution

  • column.formatter can help you. There's a online demo: this