asafdav / ng-csv

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

feat(skip-empty) added new option to skip downloading empty CSV #131

Open nacmacfeegle opened 8 years ago

nacmacfeegle commented 8 years ago

Found an issue when using ng-csv to export a file in conjunction with some validation. I was finding that the ng-csv would still trigger the download, even when the validation rules were failing (meaning underlying data was empty)

The behaviour I was seeking was to prevent the download in this case.

This PR provides the behaviour by adding a new attribute "skip-empty" (default false). When the directive is set, the CSV file will only be delivered to the browser when there is actual content.

chenchenick commented 8 years ago

I was checking on this too. A new attribute is a good idea. But instead of checking content in doClick(), I prefer to do it at stringify function by checking arrData length. This will avoid header only situation.