exporterAllDataFn event fires only when we have more than one page : when i reduce the page size and i have two pages it fires but when i have only one page it doesn't fire.i have some code in exporterAllDataFn that must be run each time . is there any solution or other way to run some piece of code before exporting ?!!
Asked
Active
Viewed 634 times
1 Answers
0
you can use it to call a new function which you can handle the downloading of CSV:
exporterAllDataFn: function () {
$scope.downloadCSV();
}
and handled the csv here:
$scope.downloadCSV = function () {
paramsObj['query'] = $scope.keyword;
$scope.downloadCSVPromise = Material.query(paramsObj, function (response) {
if (response && response.partSearchList && response.partSearchList.length > 0) {
$scope.noData = false;
$scope.numFound = response.numFound;
**var csv = JSON2CSV(response.partSearchList);**
//window.open("data:text/csv;charset=utf-8," + escape(csv))
if (window.navigator.msSaveOrOpenBlob) {
var blob_ie = new Blob([decodeURIComponent(encodeURI(csv))], {
type: "text/csv;charset=utf-8;"
});
navigator.msSaveBlob(blob_ie, 'FileName.csv');
}
var date = new Date();
var today = date.toString().substr(4,20);
var regex = new RegExp(" ", 'g');
today = today.replace(regex, '_');
var fileNm = 'AGSExtract_'+today+'.csv';
var downloadLink = document.createElement("a");
var blob = new Blob(["\ufeff", csv]);
var url = URL.createObjectURL(blob);
downloadLink.href = url;
downloadLink.download = fileNm;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
} else {
$scope.noData = true;
}
});
};
Above solution is for server side full data, if you are using client side pagination then check for JSON2CSV and pass the $scope variable which has the table data.
Hope this helps :)

GOK
- 2,338
- 6
- 34
- 63
-
my problem is that exporterAllDataFn code does not even fire when we have one page – parichehr.mohebbi Jul 27 '17 at 12:09
-
Can you make a plunker or jsfiddle to show your code then may be i could help because i have implemented the same and works smooth silk. – GOK Jul 28 '17 at 06:06