Export JSON Data to CSV File in AngularJs based on ui-grid's every row id
I need a CSV export option in angularjs 1.0 UI-grid's every row, where the user will click on that button, and based on the id server will respond a JSON based data then it should download in CSV format.
See the below image with Export CSV button.
Here's what I have tried so far:
Grid's column Definition
{
field: "actions", "name": "Action",
cellTemplate: '<button type="button" field-separator="," ng-click="funcExport({{row.entity._id}})" csv-header="exportHeader" ng-csv="export" filename="Sample.csv">Export CSV</button>',
width: "170"
}
Export Function To CSV: Currently JSON data is not based on id but in static for demonstration.
/*Function to export*/
var funcExport = function (id) {
$scope.exportarray = [];
$scope.exportHeader = [];
$scope.export = [];
$scope.exportHeader = ['Licence', 'Condition'];
$scope.exportarray = [{ "Licence": "229973", "Condition": "Usage" }, { "Licence": "24141", "Condition": "Level" }];
$scope.export = $scope.exportarray;
}
Any help would be appreciated!!
