我正在尝试使用ngTableExport plugin for angularjs从ng-table
导出数据,但这只会从1页导出数据。我正在寻找一个从表中导出所有数据的解决方案(包括分页数据,它也有排序或过滤数据,所以不能直接使用数组)。
下面我给出了我的代码,不知何故我的plunker link无效,但我可以在我的本地代码库上进行导出。
<a class="btn btn-primary" ng-mousedown="csv.generate()" ng-href="{{ csv.link() }}" download="myreport.csv">Export</a>
<table ng-table="tableParams" show-filter="false" class="table" export-csv="csv">
<tr ng-repeat="item in $data" height="10px">
<td data-title="'Date'">{{translate(item[0])}}</td>
<td data-title="'Tasks Run Count'">{{item[1]}}</td>
</tr>
</table>
$scope.translate = function(value) {
if (value === null || value === undefined)
return value;
var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var myDate = new Date(value);
return myDate.getDate() + " " + monthNames[myDate.getMonth()] + " " + myDate.getFullYear();
}
$scope.tasksRunData = [
[1412582400000, 135, 1412582400000, 9],
[1412586000000, 324, 1412586000000, 144],
[1412589600000, 324, 1412589600000, 108],
[1412593200000, 324, 1412593200000, 36],
[1412596800000, 324, 1412596800000, 54],
[1412600400000, 324, 1412600400000, 36],
[1412604000000, 324, 1412604000000, 36],
[1412607600000, 324, 1412607600000, 36],
[1412611200000, 324, 1412611200000, 36],
[1412614800000, 324, 1412614800000, 36],
[1412618400000, 324, 1412618400000, 36],
[1412622000000, 324, 1412622000000, 36],
[1412625600000, 324, 1412625600000, 36],
[1412629200000, 198, 1412629200000, 36],
[1412632800000, 108, 1412632800000, 36],
[1412636400000, 306, 1412636400000, 36],
[1412640000000, 324, 1412640000000, 153],
[1412643600000, 324, 1412643600000, 117],
[1412647200000, 288, 1412647200000, 36],
[1412650800000, 189, 1412650800000, 36],
[1412654400000, 324, 1412654400000, 36],
[1412658000000, 324, 1412658000000, 36],
[1412661600000, 324, 1412661600000, 36],
[1412665200000, 324, 1412665200000, 36],
[1412668800000, 324, 1412668800000, 36],
[1412672400000, 324, 1412672400000, 135],
[1412676000000, 324, 1412676000000, 117],
[1412679600000, 324, 1412679600000, 36],
[1412683200000, 306, 1412683200000, 54],
[1412686800000, 324, 1412686800000, 36],
[1412690400000, 324, 1412690400000, 36],
[1412694000000, 324, 1412694000000, 36],
[1412697600000, 324, 1412697600000, 36],
[1412701200000, 324, 1412701200000, 36],
[1412704800000, 324, 1412704800000, 36],
[1412708400000, 324, 1412708400000, 36],
[1412712000000, 324, 1412712000000, 36],
[1412715600000, 324, 1412715600000, 36],
[1412719200000, 324, 1412719200000, 36],
[1412722800000, 324, 1412722800000, 36],
[1412726400000, 324, 1412726400000, 162],
[1412730000000, 324, 1412730000000, 108],
[1412733600000, 324, 1412733600000, 36],
[1412737200000, 324, 1412737200000, 36],
[1412740800000, 324, 1412740800000, 36],
[1412744400000, 324, 1412744400000, 36],
[1412748000000, 324, 1412748000000, 36],
[1412751600000, 324, 1412751600000, 36],
[1412755200000, 324, 1412755200000, 36],
[1412758800000, 324, 1412758800000, 135],
[1412762400000, 324, 1412762400000, 117],
[1412766000000, 324, 1412766000000, 36],
[1412769600000, 324, 1412769600000, 54],
[1412773200000, 324, 1412773200000, 36],
[1412776800000, 297, 1412776800000, 36],
[1412780400000, 324, 1412780400000, 36],
[1412784000000, 324, 1412784000000, 36],
[1412787600000, 324, 1412787600000, 36],
[1412791200000, 324, 1412791200000, 36],
[1412794800000, 279, 1412794800000, 27],
[1412798400000, 324, 1412798400000, 36],
[1412802000000, 324, 1412802000000, 36],
[1412805600000, 324, 1412805600000, 36],
[1412809200000, 324, 1412809200000, 36],
[1412812800000, 324, 1412812800000, 126],
[1412816400000, 324, 1412816400000, 144],
[1412820000000, 324, 1412820000000, 36],
[1412823600000, 324, 1412823600000, 36],
[1412827200000, 324, 1412827200000, 36],
[1412830800000, 324, 1412830800000, 36],
[1412834400000, 324, 1412834400000, 36],
[1412838000000, 297, 1412838000000, 36],
[1412841600000, 324, 1412841600000, 36],
[1412845200000, 324, 1412845200000, 135],
[1412848800000, 324, 1412848800000, 117],
[1412852400000, 324, 1412852400000, 36],
[1412856000000, 324, 1412856000000, 54],
[1412859600000, 324, 1412859600000, 36],
[1412863200000, 324, 1412863200000, 36],
[1412866800000, 324, 1412866800000, 36],
[1412870400000, 324, 1412870400000, 36],
[1412874000000, 324, 1412874000000, 36],
[1412877600000, 162, 1412877600000, 18]
];
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
total: $scope.tasksRunData.length, // length of data
counts: [],
getData: function($defer, params) {
//console.log($scope.tasksRunData.length);
params.total($scope.tasksRunData.length);
$defer.resolve($scope.tasksRunData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
$scope.exportPdf = function($event) {
alert("Export to pdf click handler");
}
答案 0 :(得分:2)
我在way here
找到了davisford我做了一些相当大的改变 - 也就是说,我需要修复它以使用ng-table的寻呼机。如果启用了寻呼机,则导出插件只会导出一页数据。我的解决方法主要是重写,并不完美,但似乎对我有用。
由于插件擦除HTML表数据,诀窍是强制表关闭寻呼机,让浏览器重新渲染整个表,然后才解析表(之后恢复寻呼机,好看)和所有)。
forked repo here,对一些人进行了一些改进。
也欢迎其他相关解决方案。
答案 1 :(得分:0)
在ng-table
中添加了一个全局变量var selectedEntries =''“;
然后在ng-table
中编辑以下函数function getData(data,params){ if(data == null){ return []; }
var options = angular.extend({}, defaultDataOptions, params.settings().dataOptions);
var fData = options.applyFilter ? applyFilter(data, params) : data;
var orderedData = options.applySort ? applySort(fData, params) : fData;
selectedEntries = orderedData;
return options.applyPaging ? applyPaging(orderedData, params) : orderedData;
}
然后将以下函数添加到ng-table
this.orderedData = function(){ return selectedEntries };
您可以从控制器获取所选条目,如下所示
$ scope.self.tableParams.orderedData();