asafdav / ng-csv

Simple directive that turns arrays and objects into downloadable CSV files
MIT License
573 stars 215 forks source link

headers generated with "csv-label" do not follow order set by "csv-column-order" #134

Open bchoii opened 8 years ago

bchoii commented 8 years ago

I am able to generate a csv with headers "A, B, C" via "csv-label = true"

If I additionally specify a column order via "csv-column-order = C, B, A", the body of the csv is ordered correctly (C, B, A), but the header remains as "A, B, C".

I would expect the header to follow the column order specified, as with the body of the csv.

shaohaolin commented 8 years ago

@bchoii Current version: csv-label does not support reorder specify by csv-column-order. The thing is if you already know the order or column, you can set it to csv-header as well. Then don't use cdv-label attribute.

bchoii commented 8 years ago

A workaround exists, of course. That is not the argument for raising this issue.

  1. The results of the above combination of parameters results in output of the following : Header A, Header B, Header C Data C, Data B, Data A ... This output violates Principle of Least Surprise. I would not expect a situation where this form of output is desired, and thus need to be supported.
  2. The proposed workaround violates DRY.
shaohaolin commented 8 years ago

@bchoii I totally agreed with you. Before I thought you might just need to find a walkaround for your application, and that's why I provided my solution. Now, I had made a hotfix for this issue. Thank you again!

shaohaolin commented 8 years ago

@asafdav I think this issue can close now.