Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tranpose react-csv list

I am using the react-csv package to download a list of values stored in an array in a React app I am making like so:

<CSVLink data={[applicableCriteria]}>Download</CSVLink>

When I click Download and view the contents, I get a long row of all the list contents. Rather than being one long row, I would prefer one long column with the contents from my array. Is there a good way to transpose the 1-D array to accomplish this goal? Thank you.

applicableCriteria is an array of numbers, e.g., ["1.1.1", "1.1.2", "1.1.3", ... ].

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

it is because according to the documentation when you pass in an array of arrays
i.e [["1.1.1", "1.1.2", "1.1.3", ... ]] each array in the main array is one row.
Therefore you will need to convert to [["1.1.1"],["1.1.2"],["1.1.3"], ... ] format. Now there are multiple rows with 1 column.

<CSVLink data={applicableCriteria.map(x => [x])}>Download</CSVLink>

Edit react-csv (forked)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading