coston / json-to-csv-export

A function to easily generate csv downloads of your json data. ✨
https://json-to-csv-export.coston.io
MIT License
83 stars 24 forks source link

Hiding first CSV file row #37

Closed Vladichik closed 2 years ago

Vladichik commented 2 years ago
Screen Shot 2022-09-13 at 9 12 53

When exporting to CSV it generates first row with columns indexes. Please add the ability to hide it. Thanks

This is the PR with suggested change. https://github.com/coston/json-to-csv-export/pull/36

coston commented 2 years ago

Hey @Vladichik, is this row of column indexes in your data? Please share the json you are using.

Vladichik commented 2 years ago

Hello @coston my json does not contain indexes row. Please see an example of one of my JSONs

[ [ "DATE", "WIDGET SEEN", "ENGAGEMENT", "CONVERSION", "SUBSCRIPTIONS", "WIDGET START", "EFFECTIVE CTR", "COMPLETION RATE", "ADDED TIME" ], [ "Sep 12, 2022", 170, 98, 0, 0, 36, 0.21176470588235294, 0.3611111111111111, "0:0min" ], [ "Sep 11, 2022", 184, 46, 0, 0, 36, 0.1956521739130435, 0.16666666666666666, "0:0min" ], [ "Sep 10, 2022", 372, 92, 0, 1, 59, 0.1586021505376344, 0.3050847457627119, "0:0min" ], [ "Sep 9, 2022", 334, 71, 0, 0, 56, 0.16766467065868262, 0.32142857142857145, "0:0min" ], [ "Sep 8, 2022", 268, 53, 0, 0, 50, 0.1865671641791045, 0.5, "0:0min" ], [ "Sep 7, 2022", 663, 240, 0, 0, 215, 0.32428355957767724, 0.25116279069767444, "12:19:24h" ], [ "Sep 6, 2022", 26176, 11733, 0, 1, 11715, 0.4475473716381418, 0.22185232607767819, "5:21:0h" ] ]

coston commented 2 years ago

Cool! Thank you for that JSON sample, @Vladichik. Currently, this lib only supports an array of objects. I will add my feature feedback to your PR.

Vladichik commented 2 years ago

Hey @coston thanks for the update. I've installed the new version of the lib which you've released yesterday. But it throws me this exception:

SyntaxError: Unexpected token 'export' at wrapSafe (internal/modules/cjs/loader.js:1001:16) at Module._compile (internal/modules/cjs/loader.js:1049:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:12) at Module.require (internal/modules/cjs/loader.js:974:19) at require (internal/modules/cjs/helpers.js:101:18) at Object.json-to-csv-export (/app/.next/server/pages/_app.js:1805:18) at __webpack_require__ (/app/.next/server/webpack-runtime.js:33:42) at eval (webpack-internal:///./components/GenericTable/ExportToCsvButton.tsx:12:76) { page: '/' } /app/node_modules/json-to-csv-export/dist/index.js:34 export default csvDownload; ^^^^^^^^ I use the same typescript target es2015, and node version 16. If I change function export to this: export { csvDownload }; instead of this export default csvDownload; everything works fine

coston commented 2 years ago

@Vladichik thanks for the callout. The new tsconfig was not configured properly. I'm now outputting both esm and cjs. Would you mind trying again json-to-csv-export@2.0.2?

Vladichik commented 2 years ago

Hey @coston , yeah, looks like it works now