-1

I have an application where I make a http request from angularjs to a Java Application to fetch the data from DB.

I am getting the json as reponse in json array format.

[ {
"pumpId": 33,
"pVVoltage": "214",
"pVCurrent": "0",
"epochTime": 1482690480000
},
  {
"pumpId": 33,
"pVVoltage": "214",
"pVCurrent": "0",
"epochTime": 1482690480000
}
]

Task: On clicking Download button, angularjs controller can convert json object array to csv and give option to download this file to user.

HTML:

<button type="button" class="btn btn-primary btn-sm" ng-click="get_report(report_from_time, report_to_time)">Download</button>

get_report() have the json data.

PumpService.getReport($scope.id, $scope.timestamp_report_from_time, $scope.timestamp_report_to_time).success(function (data) {
                $scope.reportData = data;
            }).error(function (error) {
                console.error('ERROR OCCURED:', +error);
            })

What I need:

  1. Way to convert the json array into csv file in angularjs controller.

  2. On clicking Download button, this converted csv file can be downloaded into local system. Any guidance would be highly appreciated.

5
  • 1
    So whats the actual question, at the current state your post is too broad. Commented Jan 18, 2017 at 12:06
  • I need to export the converted csv file. Simply means, I have the json data, I need to convert this json data into csv and export (download). Commented Jan 18, 2017 at 12:08
  • I hope you do not expect someone to post the complete answer for you. I suggest you first find out how to do the conversion and how to create downloadable files. If you then run into a specific problem come back and create a new question. Commented Jan 18, 2017 at 12:11
  • thanks a lot. @Altoyyr you just opened my eyes. Commented Jan 18, 2017 at 12:15
  • Possible duplicate of Export to xls using angularjs Commented Jan 20, 2017 at 19:59

1 Answer 1

0

Try this http://ngmodules.org/modules/ng-csv

For working example - https://asafdav.github.io/ng-csv/example/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.