问题
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?
回答1:
column.formatter can help you. There's a online demo: this
回答2:
Here are the sample code in rendor method
render () {
let columns = []
columns = [
{ name: 'createAt',
displayName: 'my-Date',
dataFormat: function callback (cell, row, rowIndex, colIndex) { moment(cell).format('DD.MM.YYYY h:mm') },
hideFilter: true,
isKey: true,
width: '140'
}]
来源:https://stackoverflow.com/questions/51278910/how-to-use-the-moment-library-in-react-bootstrap-tables-column-definition