asafdav / ng-csv

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

export more than 1 files on single click #140

Open pinderko opened 8 years ago

pinderko commented 8 years ago

Hi,

it's possible export more csvs on one click. I need export data from child's table and also need to export parent's table in the same time. Is it possible? Thanks for your answer.

abhisheksimion commented 8 years ago

I had a similar requirement to download a master and child table's data in 2 separate csv's. So below is an example how I did it. Using AngularJs. It can be done with simple javascript also.

<img id="masterReportDownload" title="Download as CSV file" alt="Download as CSV file" ng-src="{{downloadImage}}" ng-csv="getExportData()" csv-header="getExportDataHeader()" filename="{{exportFilename}}">
<img id="childReportDownload" title="Download as CSV file" alt="Download as CSV file" ng-src="{{downloadImage}}" ng-csv="getExportChildData()" csv-header="getExportChildDataHeader()" filename="{{exportChildFilename}}">

$scope.getExportData = function(data) {
    var arr = [];
    ...
    $timeout(function() {
        angular.element('#childReportDownload').triggerHandler('click');
    }, 50);
    ...

}