Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accepting nested IDs in header object #34

Closed
zoranlorkovic opened this issue Jan 10, 2020 · 4 comments
Closed

Accepting nested IDs in header object #34

zoranlorkovic opened this issue Jan 10, 2020 · 4 comments

Comments

@zoranlorkovic
Copy link

As often you need to get data from database and then export it in CSV, it would be very handy if we could put nested IDs in header object.

Example:
object = {name: Test, surname: Test, nested: {time: test}}

And our header object would look like:
header: [{id: 'name', title: 'First name' }, {id: 'surname', title: 'Last name'}, {id: 'nested.time', title:'My time'}]

Does this make sense?

@ryu1kn
Copy link
Owner

ryu1kn commented Jan 12, 2020

Thanks @zoranlorkovic for the suggestion. Perhaps we also need to provide an option to overwrite the character used to separate key names as nested.time can actually be a key for someone.

ryu1kn added a commit that referenced this issue Jan 18, 2020
ryu1kn added a commit that referenced this issue Jan 18, 2020
ryu1kn added a commit that referenced this issue Jan 18, 2020
ryu1kn added a commit that referenced this issue Jan 18, 2020
@ryu1kn
Copy link
Owner

ryu1kn commented Jan 18, 2020

Released as v1.6.0. Let me know if there's any issue 👍

@ryu1kn ryu1kn closed this as completed Jan 18, 2020
@kazeemOnis
Copy link

Hi good day, I just tried

example object:  {
  name: 'SSL Certificate',
  stock: null,
  price: 3650,
  ProductCategory: { 
     name: 'All',
  }
 },
header = [
  { id: 'name', title: 'name' },
  { id: 'ProductCategory.name', title: 'category' },
  { id: 'price', title: 'price' },
  { id: 'stock', title: 'stock' },
 ];

but the category column always comes out empty.

@ryu1kn
Copy link
Owner

ryu1kn commented Jun 1, 2020

Hi @kazeemOnis , you need to specify headerIdDelimiter: '.'. I didn't want to make . as a default value, as it had introduced a breaking change otherwise.

  • headerIdDelimiter <string> (optional)

    Default: undefined. Give this value to specify a path to a value in a nested object.

https://github.com/ryu1kn/csv-writer/blob/ffd2a2d77426a38d971ed3fa3e58357de7c19f45/README.md#createobjectcsvwriterparams

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants