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

Change order of columns #23

Closed
sanderheilbron opened this issue May 31, 2017 · 15 comments
Closed

Change order of columns #23

sanderheilbron opened this issue May 31, 2017 · 15 comments

Comments

@sanderheilbron
Copy link

Would it be possible to set a specific order of columns?

@kaue
Copy link
Owner

kaue commented Jun 2, 2017

@sanderheilbron Currently only using the option
orderHeaders - Boolean The most used columns are shown first. (defaults to false).

@sanderheilbron
Copy link
Author

Thanks @kauegimenes, but that does not always result in a legible document, and requires switching columns inside Excel, Numbers or Google Sheets.

@kaue
Copy link
Owner

kaue commented Jun 3, 2017

@sanderheilbron This would work for you?

var jsonexport = require('jsonexport');

var contacts = [{
    name: 'Bob',
    lastname: 'Smith',
    address: {
       number: 1 
    }
},{
    name: 'James',
    lastname: 'David'
},{
    name: 'Robert',
    lastname: 'Miller'
},{
    name: 'David',
    lastname: 'Martin'
}];

jsonexport(contacts, {
   headers: ['lastname', 'name', 'address.number'] 
},function(err, csv){
    if(err) return console.log(err);
    console.log(csv);
});

@kaue kaue mentioned this issue Jun 6, 2017
@kaue
Copy link
Owner

kaue commented Jun 6, 2017

@sanderheilbron In v2.0.0 you can use the headers option to change the order.

@kaue kaue closed this as completed Jun 6, 2017
@sanderheilbron
Copy link
Author

Hi @kauegimenes I've used your code example, and nine times out of ten the order of headers is correct. I noticed that the order could change sometimes because of the data set, but this is no issue for me.

Before using this header option it was possible to rename the headers. I would like to know if there is still a possibilty to change the header name?

Thanks for your effort and the v2.0.0 update!

@sanderheilbron
Copy link
Author

Hi @kauegimenes v2.0.2 supports my code to rename headers.

@kaue
Copy link
Owner

kaue commented Jun 6, 2017

@sanderheilbron Currently there is no way to rename headers, i will see if i can add this option later.
About the incorrect order, can you help me reproduce this bug?

@kaue
Copy link
Owner

kaue commented Jun 6, 2017

@sanderheilbron v2.0.1 and v2.0.2 was only to get better performace.

@sanderheilbron
Copy link
Author

@kauegimenes v2.0.2 was the latest version when I installed the module. Just wanted to inform you about it.

Yes, I will check which data set results in a different order of headers.

@kaue
Copy link
Owner

kaue commented Jun 6, 2017

@sanderheilbron What you think about this implementation to rename headers #25 ?

@sanderheilbron
Copy link
Author

@kauegimenes Looks awesome! A lot cleaner than my current solution.

@kaue
Copy link
Owner

kaue commented Jun 6, 2017

@sanderheilbron You should be able to use it with v2.0.4

@sanderheilbron
Copy link
Author

@kauegimenes I've checked all my test data sets, but none of those sets result in a incorrect order of headers. Consider this issue as resolved.

@kaue
Copy link
Owner

kaue commented Jun 6, 2017

@sanderheilbron Thanks for the update.

Feel free to create another issue if you think about another useful feature!

@sanderheilbron
Copy link
Author

@kauegimenes I've tested the rename header option and it works like a charm. Thanks!!!

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

2 participants