Search code examples
javascriptreactjsdatatablereact-bootstrapreact-bootstrap-table

Error displaying dates from database in reactjs


I'm developing an application in React.Js.

When I select and save the dates using react-date-picker, saved well in the database. But when I show them with react-bootstrap-table-next and react-bootstrap/Table, don't show correctly.

enter image description here

For react-date-picker:

...
<DatePicker onChange={d => setDt(d)} value={date} />

For react-bootstrap-table-next:

<BootstrapTable
  bootstrap4
  keyField="id"
  data={data}
  columns={columns}
  pagination={paginationFactory(options)}
 />

For react-bootstrap/Table:

{
  array.map(item => {
    return <tr>
             <td>{item.id}</td>
             <td>{item.date}</td>
             <td>{item.hour}</td>
           </tr>

  })
}

It seems to be a problem in how it reads the date value.

How can I solve this, suggestions?


Solution

  • The solution I found temporarily (maybe that's the way to do it), was to use moment, as suggested in How to use the moment library in React Bootstrap table's column definition?

    I have to format the cell:

    moment(cell).format("YYYY-MM-DD")
    

    EDIT: use dayjs