Reputation: 7127
I'm trying to export a set of data to a excel sheet in my react application. I'm using react-data-export
to do this.
https://github.com/rdcalle/react-export-excel/blob/HEAD/examples/simple_excel_export_02.md
I'm mapping my data object as follows
const formData = [];
pageFeedbackListData.map((data, key) => {
formData.push([data.customer_contact,
data.customer_name,
data.form_name,
data.optional_feedback,
data.time,
data.total_average])
})
And using it like this
const dataSet1 = [{
columns: ["Customer Contact", "Customer Name", "Form Name", "Optional Feedback", "Time", "Total Average"],
data: [formData]
}];
when i console my formData it gives a output like this
0: (6) ["ergerg", "ergeg", "Test", "wgrgegerg", 1565409622210, "4.3"]
1: (6) ["[email protected]", "Mali", "Test", "Now you can browse privately, and other people who…downloads and bookmarks will be saved. Learn more", 1565409667623, "4.3"]
2: (6) ["N/A", "N/A", "Mali", "frwef", 1565409698437, "5.0"]
3: (6) ["N/A", "N/A", "Hotel", "Best
But my excel sheet works if i use like this
data: [formData[0],formData[1],formData[2],formData[3]]
How can i map my dataset so it produces a array like the above one without having to manually use array position.
Upvotes: 0
Views: 1496
Reputation: 111
There is a problem in the way you pass the formData to the dataSet, you wrap your formData in additional array, but your formData already has a correct structure
const dataSet1 = [{
columns: ["Customer Contact", "Customer Name", "Form Name", "Optional Feedback", "Time", "Total Average"],
data: [formData] //<---- here is the problem
}];
just change it to
const dataSet1 = [{
columns: ["Customer Contact", "Customer Name", "Form Name", "Optional Feedback", "Time", "Total Average"],
data: formData
}];
You are creating an array with all your formData at 0 index
Upvotes: 1