Reputation: 11
I want to export a table whose data is coming from an API. I want to display data of three attributes of the API in a single column (FirstName, MiddleName, LastName as FullName). Also, there is a moment object coming from it, which I want to format into date and time columns separately using the same react-csv Library.
const dataToExport = data.map((value:any) => {return {
...value,
LoginTime:moment(value.Login).format("hh:mm A"),
LoginDate:moment(value.Login).format("DD/MM/YYYY") // There are no dataIndexes LoginTime and LoginDate. Login is the attribute (moment object) coming from the API.
}});
Upvotes: 0
Views: 916
Reputation: 297
you can follow my ideal
let newData = oldData.map(item => {
...item,
newProperty: custom value
})
// delete some property don't need
delete newData.oldProperty
<CSVLink
data={newData}
filename={"my-file.csv"}
className="btn btn-primary"
target="_blank"
>
Upvotes: 0