[Table] Export table contents as CSV

This commit is contained in:
Victor Woeltjen 2016-05-25 13:54:10 -07:00
parent f21f22d95c
commit 699f6ba458
2 changed files with 15 additions and 3 deletions

View File

@ -12,7 +12,7 @@ define(
* @param element
* @constructor
*/
function MCTTableController($scope, $timeout, element) {
function MCTTableController($scope, $timeout, element, exportService) {
var self = this;
this.$scope = $scope;
@ -47,7 +47,13 @@ define(
setDefaults($scope);
$scope.exportAsCSV = function () {
window.alert("Export!");
var headers = $scope.headers;
exportService.exportCSV($scope.displayRows.map(function (row) {
return headers.reduce(function (r, header) {
r[header] = row[header].text;
return r;
}, {});
}), { headers: headers });
};
$scope.toggleSort = function (key) {

View File

@ -81,7 +81,13 @@ define(
return {
restrict: "E",
template: TableTemplate,
controller: ['$scope', '$timeout', '$element', MCTTableController],
controller: [
'$scope',
'$timeout',
'$element',
'exportService',
MCTTableController
],
scope: {
headers: "=",
rows: "=",