exporterAllDataFn事件仅在我们有多个页面时触发:当我减少页面大小并且我有两个页面时它会触发但是当我只有一个页面时它不会触发。我在exporterAllDataFn中有一些代码必须每次都跑。是否有任何解决方案或其他方式在导出之前运行一些代码?!!
答案 0 :(得分:0)
您可以使用它调用一个新功能,您可以处理CSV的下载:
exporterAllDataFn:function(){
$scope.downloadCSV();
}
并在此处理了csv:
$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;
}
});
};
上述解决方案是针对服务器端的完整数据,如果您使用客户端分页,则检查JSON2CSV并传递具有表数据的$ scope变量。
希望这会有所帮助:)