Angular – ui-grid – Dynamically Changing The File Name when Exporting CSV/PDF File

Sunday, September 20, 2015

Hi guys, here’s a quick tip for dynamically changing CSV or PDF file name. Trying to make this work comes with a price, there are couple of steps you need to make before you can change the file name.First of all you need to inject uiGridExporterService service that holds all the export methods like load data, get column headers, get export data object ,CSV content and finally you can call the downloadFile function that accepts file name as a first argument. Example: var app = angular.module('app', );app.controller('MainCtrl', ['$scope','uiGridExporterConstants','uiGridExporterService', function ($scope,uiGridExporterConstants,uiGridExporterService) { $scope.exportCSV = function(){...
no comments

Angular – ui-grid – Programmatically Trigger Download of CSV/PDF File

Saturday, September 19, 2015

Hi guys, here’s a quick tip for programmatically triggering a download of csv or pdf file. Code example:HTML: <div ng-controller="MainCtrl"> <div ui-grid="gridOptions" ui-grid-selection ui-grid-exporter class="grid"></div> <br/> <button ng-click="downloadCSV()">Download CSV</button> <button ng-click="downloadPDF()">Download PDF</button></div> JavaScript:Inside your controller you need to use gridApi object and call the exporter object who has the the csvExport function and pdfExport function, both function accept 2 string arguments, ‘rowTypes’ and ‘colTypes’ : Public Api for exporter feature $scope.downloadCSV = function(){$scope.gridApi.exporter.csvExport(uiGridExporterConstants.VISIBLE,uiGridExporterConstants.ALL);}scope.downloadPDF = function(){$scope.gridApi.exporter.pdfExport(uiGridExporterConstants.VISIBLE,uiGridExporterConstants.ALL);} Live example:http://plnkr.co/edit/iPSpgLIczvdFghhmHXCk?p=preview   good luck :)
no comments