Ad
How To Give Date Format To React-csv Column
I am trying to export data as csv file . I am using react-csv
library for it everything is working fine but I am face to date format. I tried but didn't find any proper solution . could someone please help me .
Code
headers = [
{
label: "id",
key: "id"
},
{
label: "Type",
key: "ptype"
},
{
label: "Sub Type",
key: "subtype"
},
{
label: "Date",
key: moment("createdAt").format("YYYY-MM-DD")
},
}
It not working it give me empty column when I write key with just createdAt
it give me date in this format 2019-09-13T06:34:33.000Z
I want date in readable format
Ad
Answer
You cannot format cell in your header
array. header
array is just to represent the column name in csv
file.
You need to actually format your data before providing to CSVLink
.
data = data.map(row => ({...row, createdAt: moment(row.createdAt).format("YYYY-MM-DD")}))
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad