@everymatrix/stage-mm-verification-report 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chunk-A3NTIEMP.js +1 -0
- package/chunk-CAY35YP7.js +7 -0
- package/chunk-H3QHLLCN.js +1 -0
- package/chunk-KE4BCZO4.js +851 -0
- package/chunk-OHPEWN32.js +1198 -0
- package/chunk-WSQOM5HU.js +1 -0
- package/component-lib.js +1 -0
- package/index.html +12 -0
- package/main.js +3264 -0
- package/modules/angular/LICENSE.md +21 -0
- package/modules/angular/README.md +67 -0
- package/modules/angular/angular-csp.css +25 -0
- package/modules/angular/angular.js +36600 -0
- package/modules/angular/angular.min.js +352 -0
- package/modules/angular/angular.min.js.gzip +0 -0
- package/modules/angular/angular.min.js.map +8 -0
- package/modules/angular/bower.json +9 -0
- package/modules/angular/index.js +2 -0
- package/modules/angular/package.json +25 -0
- package/modules/angular-ui-grid/CHANGELOG.md +1973 -0
- package/modules/angular-ui-grid/README.md +59 -0
- package/modules/angular-ui-grid/css/ui-grid.cellnav.css +25 -0
- package/modules/angular-ui-grid/css/ui-grid.cellnav.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.core.css +866 -0
- package/modules/angular-ui-grid/css/ui-grid.core.min.css +5 -0
- package/modules/angular-ui-grid/css/ui-grid.edit.css +23 -0
- package/modules/angular-ui-grid/css/ui-grid.edit.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.empty-base-layer.css +6 -0
- package/modules/angular-ui-grid/css/ui-grid.empty-base-layer.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.expandable.css +16 -0
- package/modules/angular-ui-grid/css/ui-grid.expandable.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.exporter.css +0 -0
- package/modules/angular-ui-grid/css/ui-grid.exporter.min.css +0 -0
- package/modules/angular-ui-grid/css/ui-grid.grouping.css +3 -0
- package/modules/angular-ui-grid/css/ui-grid.grouping.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.importer.css +0 -0
- package/modules/angular-ui-grid/css/ui-grid.importer.min.css +0 -0
- package/modules/angular-ui-grid/css/ui-grid.move-columns.css +9 -0
- package/modules/angular-ui-grid/css/ui-grid.move-columns.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.pagination.css +299 -0
- package/modules/angular-ui-grid/css/ui-grid.pagination.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.pinning.css +67 -0
- package/modules/angular-ui-grid/css/ui-grid.pinning.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.resize-columns.css +38 -0
- package/modules/angular-ui-grid/css/ui-grid.resize-columns.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.row-edit.css +9 -0
- package/modules/angular-ui-grid/css/ui-grid.row-edit.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.selection.css +25 -0
- package/modules/angular-ui-grid/css/ui-grid.selection.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.tree-base.css +4 -0
- package/modules/angular-ui-grid/css/ui-grid.tree-base.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.tree-view.css +6 -0
- package/modules/angular-ui-grid/css/ui-grid.tree-view.min.css +1 -0
- package/modules/angular-ui-grid/css/ui-grid.validate.css +3 -0
- package/modules/angular-ui-grid/css/ui-grid.validate.min.css +1 -0
- package/modules/angular-ui-grid/fonts/ui-grid.eot +0 -0
- package/modules/angular-ui-grid/fonts/ui-grid.svg +56 -0
- package/modules/angular-ui-grid/fonts/ui-grid.ttf +0 -0
- package/modules/angular-ui-grid/fonts/ui-grid.woff +0 -0
- package/modules/angular-ui-grid/less/animation.less +85 -0
- package/modules/angular-ui-grid/less/body.less +84 -0
- package/modules/angular-ui-grid/less/cell.less +46 -0
- package/modules/angular-ui-grid/less/cellnav.less +29 -0
- package/modules/angular-ui-grid/less/core.less +11 -0
- package/modules/angular-ui-grid/less/edit.less +27 -0
- package/modules/angular-ui-grid/less/elements.less +156 -0
- package/modules/angular-ui-grid/less/emptyBaseLayer.less +8 -0
- package/modules/angular-ui-grid/less/expandable.less +29 -0
- package/modules/angular-ui-grid/less/exporter.less +4 -0
- package/modules/angular-ui-grid/less/footer.less +76 -0
- package/modules/angular-ui-grid/less/grid.less +86 -0
- package/modules/angular-ui-grid/less/grouping.less +5 -0
- package/modules/angular-ui-grid/less/header.less +250 -0
- package/modules/angular-ui-grid/less/icons.less +151 -0
- package/modules/angular-ui-grid/less/importer.less +4 -0
- package/modules/angular-ui-grid/less/main.less +2 -0
- package/modules/angular-ui-grid/less/menu.less +91 -0
- package/modules/angular-ui-grid/less/moveColumns.less +12 -0
- package/modules/angular-ui-grid/less/pagination.less +297 -0
- package/modules/angular-ui-grid/less/pinning.less +86 -0
- package/modules/angular-ui-grid/less/resizeColumns.less +53 -0
- package/modules/angular-ui-grid/less/rowEdit.less +19 -0
- package/modules/angular-ui-grid/less/rtl.less +67 -0
- package/modules/angular-ui-grid/less/selection.less +29 -0
- package/modules/angular-ui-grid/less/sorting.less +16 -0
- package/modules/angular-ui-grid/less/treeBase.less +6 -0
- package/modules/angular-ui-grid/less/treeView.less +8 -0
- package/modules/angular-ui-grid/less/validate.less +5 -0
- package/modules/angular-ui-grid/less/variables.less +90 -0
- package/modules/angular-ui-grid/package.json +144 -0
- package/modules/angular-ui-grid/ui-grid.auto-resize.js +69 -0
- package/modules/angular-ui-grid/ui-grid.auto-resize.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.cellnav.js +1181 -0
- package/modules/angular-ui-grid/ui-grid.cellnav.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.core.js +12737 -0
- package/modules/angular-ui-grid/ui-grid.core.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.css +3208 -0
- package/modules/angular-ui-grid/ui-grid.edit.js +1325 -0
- package/modules/angular-ui-grid/ui-grid.edit.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.empty-base-layer.js +178 -0
- package/modules/angular-ui-grid/ui-grid.empty-base-layer.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.expandable.js +651 -0
- package/modules/angular-ui-grid/ui-grid.expandable.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.exporter.js +1777 -0
- package/modules/angular-ui-grid/ui-grid.exporter.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.grouping.js +1291 -0
- package/modules/angular-ui-grid/ui-grid.grouping.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.importer.js +791 -0
- package/modules/angular-ui-grid/ui-grid.importer.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.infinite-scroll.js +552 -0
- package/modules/angular-ui-grid/ui-grid.infinite-scroll.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.js +30867 -0
- package/modules/angular-ui-grid/ui-grid.language.all.js +3214 -0
- package/modules/angular-ui-grid/ui-grid.language.all.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ar.js +118 -0
- package/modules/angular-ui-grid/ui-grid.language.ar.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.bg.js +115 -0
- package/modules/angular-ui-grid/ui-grid.language.bg.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.cs.js +96 -0
- package/modules/angular-ui-grid/ui-grid.language.cs.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.da.js +90 -0
- package/modules/angular-ui-grid/ui-grid.language.da.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.de.js +133 -0
- package/modules/angular-ui-grid/ui-grid.language.de.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.es-ct.js +133 -0
- package/modules/angular-ui-grid/ui-grid.language.es-ct.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.es.js +106 -0
- package/modules/angular-ui-grid/ui-grid.language.es.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.fa.js +93 -0
- package/modules/angular-ui-grid/ui-grid.language.fa.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.fi.js +76 -0
- package/modules/angular-ui-grid/ui-grid.language.fi.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.fr.js +128 -0
- package/modules/angular-ui-grid/ui-grid.language.fr.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.he.js +71 -0
- package/modules/angular-ui-grid/ui-grid.language.he.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.hy.js +76 -0
- package/modules/angular-ui-grid/ui-grid.language.hy.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.is.js +118 -0
- package/modules/angular-ui-grid/ui-grid.language.is.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.it.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.it.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ja.js +118 -0
- package/modules/angular-ui-grid/ui-grid.language.ja.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ko.js +77 -0
- package/modules/angular-ui-grid/ui-grid.language.ko.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.nl.js +91 -0
- package/modules/angular-ui-grid/ui-grid.language.nl.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.no.js +115 -0
- package/modules/angular-ui-grid/ui-grid.language.no.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.pl.js +126 -0
- package/modules/angular-ui-grid/ui-grid.language.pl.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.pt-br.js +133 -0
- package/modules/angular-ui-grid/ui-grid.language.pt-br.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.pt.js +133 -0
- package/modules/angular-ui-grid/ui-grid.language.pt.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ro.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.ro.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.rs-lat.js +126 -0
- package/modules/angular-ui-grid/ui-grid.language.rs-lat.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ru.js +115 -0
- package/modules/angular-ui-grid/ui-grid.language.ru.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.sk.js +127 -0
- package/modules/angular-ui-grid/ui-grid.language.sk.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.sv.js +126 -0
- package/modules/angular-ui-grid/ui-grid.language.sv.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ta.js +87 -0
- package/modules/angular-ui-grid/ui-grid.language.ta.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.tr.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.tr.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.ua.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.ua.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.zh-cn.js +112 -0
- package/modules/angular-ui-grid/ui-grid.language.zh-cn.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.language.zh-tw.js +77 -0
- package/modules/angular-ui-grid/ui-grid.language.zh-tw.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.min.css +5 -0
- package/modules/angular-ui-grid/ui-grid.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.move-columns.js +582 -0
- package/modules/angular-ui-grid/ui-grid.move-columns.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.pagination.js +510 -0
- package/modules/angular-ui-grid/ui-grid.pagination.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.pinning.js +281 -0
- package/modules/angular-ui-grid/ui-grid.pinning.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.resize-columns.js +574 -0
- package/modules/angular-ui-grid/ui-grid.resize-columns.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.row-edit.js +717 -0
- package/modules/angular-ui-grid/ui-grid.row-edit.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.saveState.js +831 -0
- package/modules/angular-ui-grid/ui-grid.saveState.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.selection.js +1196 -0
- package/modules/angular-ui-grid/ui-grid.selection.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.tree-base.js +1743 -0
- package/modules/angular-ui-grid/ui-grid.tree-base.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.tree-view.js +218 -0
- package/modules/angular-ui-grid/ui-grid.tree-view.min.js +6 -0
- package/modules/angular-ui-grid/ui-grid.validate.js +589 -0
- package/modules/angular-ui-grid/ui-grid.validate.min.js +6 -0
- package/package.json +8 -0
- package/polyfills.js +2 -0
- package/styles.css +1 -0
|
@@ -0,0 +1,1777 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ui-grid - v4.12.7 - 2024-04-12
|
|
3
|
+
* http://ui-grid.info/
|
|
4
|
+
* Copyright (c) 2024 ; License: MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* global ExcelBuilder */
|
|
8
|
+
/* global console */
|
|
9
|
+
|
|
10
|
+
(function () {
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @ngdoc overview
|
|
15
|
+
* @name ui.grid.exporter
|
|
16
|
+
* @description
|
|
17
|
+
*
|
|
18
|
+
* # ui.grid.exporter
|
|
19
|
+
*
|
|
20
|
+
* <div class="alert alert-success" role="alert"><strong>Stable</strong> This feature is stable. There should no longer be breaking api changes without a deprecation warning.</div>
|
|
21
|
+
*
|
|
22
|
+
* This module provides the ability to export data from the grid.
|
|
23
|
+
*
|
|
24
|
+
* Data can be exported in a range of formats, and all data, visible
|
|
25
|
+
* data, or selected rows can be exported, with all columns or visible
|
|
26
|
+
* columns.
|
|
27
|
+
*
|
|
28
|
+
* No UI is provided, the caller should provide their own UI/buttons
|
|
29
|
+
* as appropriate, or enable the gridMenu
|
|
30
|
+
*
|
|
31
|
+
* <br/>
|
|
32
|
+
* <br/>
|
|
33
|
+
*
|
|
34
|
+
* <div doc-module-components="ui.grid.exporter"></div>
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
var module = angular.module('ui.grid.exporter', ['ui.grid']);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @ngdoc object
|
|
41
|
+
* @name ui.grid.exporter.constant:uiGridExporterConstants
|
|
42
|
+
*
|
|
43
|
+
* @description constants available in exporter module
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* @ngdoc property
|
|
47
|
+
* @propertyOf ui.grid.exporter.constant:uiGridExporterConstants
|
|
48
|
+
* @name ALL
|
|
49
|
+
* @description export all data, including data not visible. Can
|
|
50
|
+
* be set for either rowTypes or colTypes
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* @ngdoc property
|
|
54
|
+
* @propertyOf ui.grid.exporter.constant:uiGridExporterConstants
|
|
55
|
+
* @name VISIBLE
|
|
56
|
+
* @description export only visible data, including data not visible. Can
|
|
57
|
+
* be set for either rowTypes or colTypes
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* @ngdoc property
|
|
61
|
+
* @propertyOf ui.grid.exporter.constant:uiGridExporterConstants
|
|
62
|
+
* @name SELECTED
|
|
63
|
+
* @description export all data, including data not visible. Can
|
|
64
|
+
* be set only for rowTypes, selection of only some columns is
|
|
65
|
+
* not supported
|
|
66
|
+
*/
|
|
67
|
+
module.constant('uiGridExporterConstants', {
|
|
68
|
+
featureName: 'exporter',
|
|
69
|
+
rowHeaderColName: 'treeBaseRowHeaderCol',
|
|
70
|
+
selectionRowHeaderColName: 'selectionRowHeaderCol',
|
|
71
|
+
ALL: 'all',
|
|
72
|
+
VISIBLE: 'visible',
|
|
73
|
+
SELECTED: 'selected',
|
|
74
|
+
CSV_CONTENT: 'CSV_CONTENT',
|
|
75
|
+
BUTTON_LABEL: 'BUTTON_LABEL',
|
|
76
|
+
FILE_NAME: 'FILE_NAME'
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @ngdoc service
|
|
81
|
+
* @name ui.grid.exporter.service:uiGridExporterService
|
|
82
|
+
*
|
|
83
|
+
* @description Services for exporter feature
|
|
84
|
+
*/
|
|
85
|
+
module.service('uiGridExporterService', ['$filter', '$q', 'uiGridExporterConstants', 'gridUtil', '$compile', '$interval', 'i18nService',
|
|
86
|
+
function ($filter, $q, uiGridExporterConstants, gridUtil, $compile, $interval, i18nService) {
|
|
87
|
+
var service = {
|
|
88
|
+
|
|
89
|
+
delay: 100,
|
|
90
|
+
type: null,
|
|
91
|
+
|
|
92
|
+
initializeGrid: function (grid) {
|
|
93
|
+
|
|
94
|
+
// add feature namespace and any properties to grid for needed state
|
|
95
|
+
grid.exporter = {};
|
|
96
|
+
this.defaultGridOptions(grid.options);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @ngdoc object
|
|
100
|
+
* @name ui.grid.exporter.api:PublicApi
|
|
101
|
+
*
|
|
102
|
+
* @description Public Api for exporter feature
|
|
103
|
+
*/
|
|
104
|
+
var publicApi = {
|
|
105
|
+
events: {
|
|
106
|
+
exporter: {
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
methods: {
|
|
110
|
+
exporter: {
|
|
111
|
+
/**
|
|
112
|
+
* @ngdoc function
|
|
113
|
+
* @name csvExport
|
|
114
|
+
* @methodOf ui.grid.exporter.api:PublicApi
|
|
115
|
+
* @description Exports rows from the grid in csv format,
|
|
116
|
+
* the data exported is selected based on the provided options
|
|
117
|
+
* @param {string} rowTypes which rows to export, valid values are
|
|
118
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
119
|
+
* uiGridExporterConstants.SELECTED
|
|
120
|
+
* @param {string} colTypes which columns to export, valid values are
|
|
121
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE
|
|
122
|
+
*/
|
|
123
|
+
csvExport: function (rowTypes, colTypes) {
|
|
124
|
+
service.csvExport(grid, rowTypes, colTypes);
|
|
125
|
+
},
|
|
126
|
+
/**
|
|
127
|
+
* @ngdoc function
|
|
128
|
+
* @name pdfExport
|
|
129
|
+
* @methodOf ui.grid.exporter.api:PublicApi
|
|
130
|
+
* @description Exports rows from the grid in pdf format,
|
|
131
|
+
* the data exported is selected based on the provided options
|
|
132
|
+
* Note that this function has a dependency on pdfMake, all
|
|
133
|
+
* going well this has been installed for you.
|
|
134
|
+
* The resulting pdf opens in a new browser window.
|
|
135
|
+
* @param {string} rowTypes which rows to export, valid values are
|
|
136
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
137
|
+
* uiGridExporterConstants.SELECTED
|
|
138
|
+
* @param {string} colTypes which columns to export, valid values are
|
|
139
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE
|
|
140
|
+
*/
|
|
141
|
+
pdfExport: function (rowTypes, colTypes) {
|
|
142
|
+
service.pdfExport(grid, rowTypes, colTypes);
|
|
143
|
+
},
|
|
144
|
+
/**
|
|
145
|
+
* @ngdoc function
|
|
146
|
+
* @name excelExport
|
|
147
|
+
* @methodOf ui.grid.exporter.api:PublicApi
|
|
148
|
+
* @description Exports rows from the grid in excel format,
|
|
149
|
+
* the data exported is selected based on the provided options
|
|
150
|
+
* @param {string} rowTypes which rows to export, valid values are
|
|
151
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
152
|
+
* uiGridExporterConstants.SELECTED
|
|
153
|
+
* @param {string} colTypes which columns to export, valid values are
|
|
154
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE
|
|
155
|
+
*/
|
|
156
|
+
excelExport: function (rowTypes, colTypes) {
|
|
157
|
+
service.excelExport(grid, rowTypes, colTypes);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
grid.api.registerEventsFromObject(publicApi.events);
|
|
164
|
+
|
|
165
|
+
grid.api.registerMethodsFromObject(publicApi.methods);
|
|
166
|
+
|
|
167
|
+
if (grid.api.core.addToGridMenu) {
|
|
168
|
+
service.addToMenu( grid );
|
|
169
|
+
} else {
|
|
170
|
+
// order of registration is not guaranteed, register in a little while
|
|
171
|
+
$interval( function() {
|
|
172
|
+
if (grid.api.core.addToGridMenu) {
|
|
173
|
+
service.addToMenu( grid );
|
|
174
|
+
}
|
|
175
|
+
}, this.delay, 1);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
defaultGridOptions: function (gridOptions) {
|
|
181
|
+
// default option to true unless it was explicitly set to false
|
|
182
|
+
/**
|
|
183
|
+
* @ngdoc object
|
|
184
|
+
* @name ui.grid.exporter.api:GridOptions
|
|
185
|
+
*
|
|
186
|
+
* @description GridOptions for exporter feature, these are available to be
|
|
187
|
+
* set using the ui-grid {@link ui.grid.class:GridOptions gridOptions}
|
|
188
|
+
*/
|
|
189
|
+
/**
|
|
190
|
+
* @ngdoc object
|
|
191
|
+
* @name ui.grid.exporter.api:ColumnDef
|
|
192
|
+
* @description ColumnDef settings for exporter
|
|
193
|
+
*/
|
|
194
|
+
/**
|
|
195
|
+
* @ngdoc object
|
|
196
|
+
* @name exporterSuppressMenu
|
|
197
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
198
|
+
* @description Don't show the export menu button, implying the user
|
|
199
|
+
* will roll their own UI for calling the exporter
|
|
200
|
+
* <br/>Defaults to false
|
|
201
|
+
*/
|
|
202
|
+
gridOptions.exporterSuppressMenu = gridOptions.exporterSuppressMenu === true;
|
|
203
|
+
/**
|
|
204
|
+
* @ngdoc object
|
|
205
|
+
* @name exporterMenuLabel
|
|
206
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
207
|
+
* @description The text to show on the exporter menu button
|
|
208
|
+
* link
|
|
209
|
+
* <br/>Defaults to 'Export'
|
|
210
|
+
*/
|
|
211
|
+
gridOptions.exporterMenuLabel = gridOptions.exporterMenuLabel ? gridOptions.exporterMenuLabel : 'Export';
|
|
212
|
+
/**
|
|
213
|
+
* @ngdoc object
|
|
214
|
+
* @name exporterSuppressColumns
|
|
215
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
216
|
+
* @description Columns that should not be exported. The selectionRowHeader is already automatically
|
|
217
|
+
* suppressed, but if you had a button column or some other "system" column that shouldn't be shown in the
|
|
218
|
+
* output then add it in this list. You should provide an array of column names.
|
|
219
|
+
* <br/>Defaults to: []
|
|
220
|
+
* <pre>
|
|
221
|
+
* gridOptions.exporterSuppressColumns = [ 'buttons' ];
|
|
222
|
+
* </pre>
|
|
223
|
+
*/
|
|
224
|
+
gridOptions.exporterSuppressColumns = gridOptions.exporterSuppressColumns ? gridOptions.exporterSuppressColumns : [];
|
|
225
|
+
/**
|
|
226
|
+
* @ngdoc object
|
|
227
|
+
* @name exporterCsvColumnSeparator
|
|
228
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
229
|
+
* @description The character to use as column separator
|
|
230
|
+
* link
|
|
231
|
+
* <br/>Defaults to ','
|
|
232
|
+
*/
|
|
233
|
+
gridOptions.exporterCsvColumnSeparator = gridOptions.exporterCsvColumnSeparator ? gridOptions.exporterCsvColumnSeparator : ',';
|
|
234
|
+
/**
|
|
235
|
+
* @ngdoc object
|
|
236
|
+
* @name exporterCsvFilename
|
|
237
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
238
|
+
* @description The default filename to use when saving the downloaded csv.
|
|
239
|
+
* This will only work in some browsers.
|
|
240
|
+
* <br/>Defaults to 'download.csv'
|
|
241
|
+
* <pre>
|
|
242
|
+
* gridOptions.exporterCsvFilename = "rows.csv"
|
|
243
|
+
* </pre>
|
|
244
|
+
* <br/>Or a function returning a string:
|
|
245
|
+
* <pre>
|
|
246
|
+
* gridOptions.exporterCsvFilename = function(grid, rowTypes, colTypes) { return "rows" + rowTypes + ".csv" };
|
|
247
|
+
* </pre>
|
|
248
|
+
*/
|
|
249
|
+
gridOptions.exporterCsvFilename = gridOptions.exporterCsvFilename ? gridOptions.exporterCsvFilename : 'download.csv';
|
|
250
|
+
/**
|
|
251
|
+
* @ngdoc object
|
|
252
|
+
* @name exporterPdfFilename
|
|
253
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
254
|
+
* @description The default filename to use when saving the downloaded pdf, only used in IE (other browsers open pdfs in a new window)
|
|
255
|
+
* <br/>Defaults to 'download.pdf'
|
|
256
|
+
* <pre>
|
|
257
|
+
* gridOptions.exporterPdfFilename = "rows.pdf"
|
|
258
|
+
* </pre>
|
|
259
|
+
* <br/>Or a function returning a string:
|
|
260
|
+
* <pre>
|
|
261
|
+
* gridOptions.exporterPdfFilename = function(grid, rowTypes, colTypes) { return "rows" + rowTypes + ".pdf" };
|
|
262
|
+
* </pre>
|
|
263
|
+
*/
|
|
264
|
+
gridOptions.exporterPdfFilename = gridOptions.exporterPdfFilename ? gridOptions.exporterPdfFilename : 'download.pdf';
|
|
265
|
+
/**
|
|
266
|
+
* @ngdoc object
|
|
267
|
+
* @name exporterExcelFilename
|
|
268
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
269
|
+
* @description The default filename to use when saving the downloaded excel, only used in IE (other browsers open excels in a new window)
|
|
270
|
+
* <br/>Defaults to 'download.xlsx'
|
|
271
|
+
* <pre>
|
|
272
|
+
* gridOptions.exporterExcelFilename = "rows.xlsx"
|
|
273
|
+
* </pre>
|
|
274
|
+
* <br/>Or a function returning a string:
|
|
275
|
+
* <pre>
|
|
276
|
+
* gridOptions.exporterExcelFilename = function(grid, rowTypes, colTypes) { return "rows" + rowTypes + ".xlsx" };
|
|
277
|
+
* </pre>
|
|
278
|
+
*/
|
|
279
|
+
gridOptions.exporterExcelFilename = gridOptions.exporterExcelFilename ? gridOptions.exporterExcelFilename : 'download.xlsx';
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @ngdoc object
|
|
283
|
+
* @name exporterExcelSheetName
|
|
284
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
285
|
+
* @description The default sheetname to use when saving the downloaded to excel
|
|
286
|
+
* <br/>Defaults to 'Sheet1'
|
|
287
|
+
* <pre>
|
|
288
|
+
* gridOptions.exporterExcelSheetName = "HitListSheet"
|
|
289
|
+
* </pre>
|
|
290
|
+
* <br/>Or a function returning a string:
|
|
291
|
+
* <pre>
|
|
292
|
+
* gridOptions.exporterExcelSheetName = function(grid, rowTypes, colTypes) { return "HitListSheet" + rowTypes };
|
|
293
|
+
* </pre>
|
|
294
|
+
*/
|
|
295
|
+
gridOptions.exporterExcelSheetName = gridOptions.exporterExcelSheetName ? gridOptions.exporterExcelSheetName : 'Sheet1';
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @ngdoc object
|
|
299
|
+
* @name exporterOlderExcelCompatibility
|
|
300
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
301
|
+
* @description Some versions of excel don't like the utf-16 BOM on the front, and it comes
|
|
302
|
+
* through as  in the first column header. Setting this option to false will suppress this, at the
|
|
303
|
+
* expense of proper utf-16 handling in applications that do recognise the BOM
|
|
304
|
+
* <br/>Defaults to false
|
|
305
|
+
*/
|
|
306
|
+
gridOptions.exporterOlderExcelCompatibility = gridOptions.exporterOlderExcelCompatibility === true;
|
|
307
|
+
/**
|
|
308
|
+
* @ngdoc object
|
|
309
|
+
* @name exporterIsExcelCompatible
|
|
310
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
311
|
+
* @description Separator header, used to set a custom column separator in a csv file, only works on MS Excel.
|
|
312
|
+
* Used it on other programs will make csv content display unproperly. Setting this option to false won't add this header.
|
|
313
|
+
* <br/>Defaults to false
|
|
314
|
+
*/
|
|
315
|
+
gridOptions.exporterIsExcelCompatible = gridOptions.exporterIsExcelCompatible === true;
|
|
316
|
+
/**
|
|
317
|
+
* @ngdoc object
|
|
318
|
+
* @name exporterMenuItemOrder
|
|
319
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
320
|
+
* @description An option to determine the starting point for the menu items created by the exporter
|
|
321
|
+
* <br/>Defaults to 200
|
|
322
|
+
*/
|
|
323
|
+
gridOptions.exporterMenuItemOrder = gridOptions.exporterMenuItemOrder ? gridOptions.exporterMenuItemOrder : 200;
|
|
324
|
+
/**
|
|
325
|
+
* @ngdoc object
|
|
326
|
+
* @name exporterPdfDefaultStyle
|
|
327
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
328
|
+
* @description The default style in pdfMake format
|
|
329
|
+
* <br/>Defaults to:
|
|
330
|
+
* <pre>
|
|
331
|
+
* {
|
|
332
|
+
* fontSize: 11
|
|
333
|
+
* }
|
|
334
|
+
* </pre>
|
|
335
|
+
*/
|
|
336
|
+
gridOptions.exporterPdfDefaultStyle = gridOptions.exporterPdfDefaultStyle ? gridOptions.exporterPdfDefaultStyle : { fontSize: 11 };
|
|
337
|
+
/**
|
|
338
|
+
* @ngdoc object
|
|
339
|
+
* @name exporterPdfTableStyle
|
|
340
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
341
|
+
* @description The table style in pdfMake format
|
|
342
|
+
* <br/>Defaults to:
|
|
343
|
+
* <pre>
|
|
344
|
+
* {
|
|
345
|
+
* margin: [0, 5, 0, 15]
|
|
346
|
+
* }
|
|
347
|
+
* </pre>
|
|
348
|
+
*/
|
|
349
|
+
gridOptions.exporterPdfTableStyle = gridOptions.exporterPdfTableStyle ? gridOptions.exporterPdfTableStyle : { margin: [0, 5, 0, 15] };
|
|
350
|
+
/**
|
|
351
|
+
* @ngdoc object
|
|
352
|
+
* @name exporterPdfTableHeaderStyle
|
|
353
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
354
|
+
* @description The tableHeader style in pdfMake format
|
|
355
|
+
* <br/>Defaults to:
|
|
356
|
+
* <pre>
|
|
357
|
+
* {
|
|
358
|
+
* bold: true,
|
|
359
|
+
* fontSize: 12,
|
|
360
|
+
* color: 'black'
|
|
361
|
+
* }
|
|
362
|
+
* </pre>
|
|
363
|
+
*/
|
|
364
|
+
gridOptions.exporterPdfTableHeaderStyle = gridOptions.exporterPdfTableHeaderStyle ? gridOptions.exporterPdfTableHeaderStyle : { bold: true, fontSize: 12, color: 'black' };
|
|
365
|
+
/**
|
|
366
|
+
* @ngdoc object
|
|
367
|
+
* @name exporterPdfHeader
|
|
368
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
369
|
+
* @description The header section for pdf exports. Can be
|
|
370
|
+
* simple text:
|
|
371
|
+
* <pre>
|
|
372
|
+
* gridOptions.exporterPdfHeader = 'My Header';
|
|
373
|
+
* </pre>
|
|
374
|
+
* Can be a more complex object in pdfMake format:
|
|
375
|
+
* <pre>
|
|
376
|
+
* gridOptions.exporterPdfHeader = {
|
|
377
|
+
* columns: [
|
|
378
|
+
* 'Left part',
|
|
379
|
+
* { text: 'Right part', alignment: 'right' }
|
|
380
|
+
* ]
|
|
381
|
+
* };
|
|
382
|
+
* </pre>
|
|
383
|
+
* Or can be a function, allowing page numbers and the like
|
|
384
|
+
* <pre>
|
|
385
|
+
* gridOptions.exporterPdfHeader: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; };
|
|
386
|
+
* </pre>
|
|
387
|
+
*/
|
|
388
|
+
gridOptions.exporterPdfHeader = gridOptions.exporterPdfHeader ? gridOptions.exporterPdfHeader : null;
|
|
389
|
+
/**
|
|
390
|
+
* @ngdoc object
|
|
391
|
+
* @name exporterPdfFooter
|
|
392
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
393
|
+
* @description The header section for pdf exports. Can be
|
|
394
|
+
* simple text:
|
|
395
|
+
* <pre>
|
|
396
|
+
* gridOptions.exporterPdfFooter = 'My Footer';
|
|
397
|
+
* </pre>
|
|
398
|
+
* Can be a more complex object in pdfMake format:
|
|
399
|
+
* <pre>
|
|
400
|
+
* gridOptions.exporterPdfFooter = {
|
|
401
|
+
* columns: [
|
|
402
|
+
* 'Left part',
|
|
403
|
+
* { text: 'Right part', alignment: 'right' }
|
|
404
|
+
* ]
|
|
405
|
+
* };
|
|
406
|
+
* </pre>
|
|
407
|
+
* Or can be a function, allowing page numbers and the like
|
|
408
|
+
* <pre>
|
|
409
|
+
* gridOptions.exporterPdfFooter: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; };
|
|
410
|
+
* </pre>
|
|
411
|
+
*/
|
|
412
|
+
gridOptions.exporterPdfFooter = gridOptions.exporterPdfFooter ? gridOptions.exporterPdfFooter : null;
|
|
413
|
+
/**
|
|
414
|
+
* @ngdoc object
|
|
415
|
+
* @name exporterPdfOrientation
|
|
416
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
417
|
+
* @description The orientation, should be a valid pdfMake value,
|
|
418
|
+
* 'landscape' or 'portrait'
|
|
419
|
+
* <br/>Defaults to landscape
|
|
420
|
+
*/
|
|
421
|
+
gridOptions.exporterPdfOrientation = gridOptions.exporterPdfOrientation ? gridOptions.exporterPdfOrientation : 'landscape';
|
|
422
|
+
/**
|
|
423
|
+
* @ngdoc object
|
|
424
|
+
* @name exporterPdfPageSize
|
|
425
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
426
|
+
* @description The orientation, should be a valid pdfMake
|
|
427
|
+
* paper size, usually 'A4' or 'LETTER'
|
|
428
|
+
* {@link https://github.com/bpampuch/pdfmake/blob/master/src/standardPageSizes.js pdfMake page sizes}
|
|
429
|
+
* <br/>Defaults to A4
|
|
430
|
+
*/
|
|
431
|
+
gridOptions.exporterPdfPageSize = gridOptions.exporterPdfPageSize ? gridOptions.exporterPdfPageSize : 'A4';
|
|
432
|
+
/**
|
|
433
|
+
* @ngdoc object
|
|
434
|
+
* @name exporterPdfMaxGridWidth
|
|
435
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
436
|
+
* @description The maxium grid width - the current grid width
|
|
437
|
+
* will be scaled to match this, with any fixed width columns
|
|
438
|
+
* being adjusted accordingly.
|
|
439
|
+
* <br/>Defaults to 720 (for A4 landscape), use 670 for LETTER
|
|
440
|
+
*/
|
|
441
|
+
gridOptions.exporterPdfMaxGridWidth = gridOptions.exporterPdfMaxGridWidth ? gridOptions.exporterPdfMaxGridWidth : 720;
|
|
442
|
+
/**
|
|
443
|
+
* @ngdoc object
|
|
444
|
+
* @name exporterPdfTableLayout
|
|
445
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
446
|
+
* @description A tableLayout in pdfMake format,
|
|
447
|
+
* controls gridlines and the like. We use the default
|
|
448
|
+
* layout usually.
|
|
449
|
+
* <br/>Defaults to null, which means no layout
|
|
450
|
+
*/
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* @ngdoc object
|
|
454
|
+
* @name exporterMenuAllData
|
|
455
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
456
|
+
* @description Add export all data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true.
|
|
457
|
+
*/
|
|
458
|
+
gridOptions.exporterMenuAllData = gridOptions.exporterMenuAllData !== undefined ? gridOptions.exporterMenuAllData : true;
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* @ngdoc object
|
|
462
|
+
* @name exporterMenuVisibleData
|
|
463
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
464
|
+
* @description Add export visible data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true.
|
|
465
|
+
*/
|
|
466
|
+
gridOptions.exporterMenuVisibleData = gridOptions.exporterMenuVisibleData !== undefined ? gridOptions.exporterMenuVisibleData : true;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @ngdoc object
|
|
470
|
+
* @name exporterMenuSelectedData
|
|
471
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
472
|
+
* @description Add export selected data as cvs/pdf menu items to the ui-grid grid menu, if it's present. Defaults to true.
|
|
473
|
+
*/
|
|
474
|
+
gridOptions.exporterMenuSelectedData = gridOptions.exporterMenuSelectedData !== undefined ? gridOptions.exporterMenuSelectedData : true;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* @ngdoc object
|
|
478
|
+
* @name exporterMenuCsv
|
|
479
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
480
|
+
* @description Add csv export menu items to the ui-grid grid menu, if it's present. Defaults to true.
|
|
481
|
+
*/
|
|
482
|
+
gridOptions.exporterMenuCsv = gridOptions.exporterMenuCsv !== undefined ? gridOptions.exporterMenuCsv : true;
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* @ngdoc object
|
|
486
|
+
* @name exporterMenuPdf
|
|
487
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
488
|
+
* @description Add pdf export menu items to the ui-grid grid menu, if it's present. Defaults to true.
|
|
489
|
+
*/
|
|
490
|
+
gridOptions.exporterMenuPdf = gridOptions.exporterMenuPdf !== undefined ? gridOptions.exporterMenuPdf : true;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* @ngdoc object
|
|
494
|
+
* @name exporterMenuExcel
|
|
495
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
496
|
+
* @description Add excel export menu items to the ui-grid grid menu, if it's present. Defaults to true.
|
|
497
|
+
*/
|
|
498
|
+
gridOptions.exporterMenuExcel = gridOptions.exporterMenuExcel !== undefined ? gridOptions.exporterMenuExcel : true;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* @ngdoc object
|
|
502
|
+
* @name exporterPdfCustomFormatter
|
|
503
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
504
|
+
* @description A custom callback routine that changes the pdf document, adding any
|
|
505
|
+
* custom styling or content that is supported by pdfMake. Takes in the complete docDefinition, and
|
|
506
|
+
* must return an updated docDefinition ready for pdfMake.
|
|
507
|
+
* @example
|
|
508
|
+
* In this example we add a style to the style array, so that we can use it in our
|
|
509
|
+
* footer definition.
|
|
510
|
+
* <pre>
|
|
511
|
+
* gridOptions.exporterPdfCustomFormatter = function ( docDefinition ) {
|
|
512
|
+
* docDefinition.styles.footerStyle = { bold: true, fontSize: 10 };
|
|
513
|
+
* return docDefinition;
|
|
514
|
+
* }
|
|
515
|
+
*
|
|
516
|
+
* gridOptions.exporterPdfFooter = { text: 'My footer', style: 'footerStyle' }
|
|
517
|
+
* </pre>
|
|
518
|
+
*/
|
|
519
|
+
gridOptions.exporterPdfCustomFormatter = ( gridOptions.exporterPdfCustomFormatter && typeof( gridOptions.exporterPdfCustomFormatter ) === 'function' ) ? gridOptions.exporterPdfCustomFormatter : function ( docDef ) { return docDef; };
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* @ngdoc object
|
|
523
|
+
* @name exporterHeaderFilterUseName
|
|
524
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
525
|
+
* @description Defaults to false, which leads to `displayName` being passed into the headerFilter.
|
|
526
|
+
* If set to true, then will pass `name` instead.
|
|
527
|
+
*
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* <pre>
|
|
531
|
+
* gridOptions.exporterHeaderFilterUseName = true;
|
|
532
|
+
* </pre>
|
|
533
|
+
*/
|
|
534
|
+
gridOptions.exporterHeaderFilterUseName = gridOptions.exporterHeaderFilterUseName === true;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* @ngdoc object
|
|
538
|
+
* @name exporterHeaderFilter
|
|
539
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
540
|
+
* @description A function to apply to the header displayNames before exporting. Useful for internationalisation,
|
|
541
|
+
* for example if you were using angular-translate you'd set this to `$translate.instant`. Note that this
|
|
542
|
+
* call must be synchronous, it cannot be a call that returns a promise.
|
|
543
|
+
*
|
|
544
|
+
* Behaviour can be changed to pass in `name` instead of `displayName` through use of `exporterHeaderFilterUseName: true`.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* <pre>
|
|
548
|
+
* gridOptions.exporterHeaderFilter = function( displayName ) { return 'col: ' + name; };
|
|
549
|
+
* </pre>
|
|
550
|
+
* OR
|
|
551
|
+
* <pre>
|
|
552
|
+
* gridOptions.exporterHeaderFilter = $translate.instant;
|
|
553
|
+
* </pre>
|
|
554
|
+
*/
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* @ngdoc function
|
|
558
|
+
* @name exporterFieldCallback
|
|
559
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
560
|
+
* @description A function to call for each field before exporting it. Allows
|
|
561
|
+
* massaging of raw data into a display format, for example if you have applied
|
|
562
|
+
* filters to convert codes into decodes, or you require
|
|
563
|
+
* a specific date format in the exported content.
|
|
564
|
+
*
|
|
565
|
+
* The method is called once for each field exported, and provides the grid, the
|
|
566
|
+
* gridCol and the GridRow for you to use as context in massaging the data.
|
|
567
|
+
*
|
|
568
|
+
* @param {Grid} grid provides the grid in case you have need of it
|
|
569
|
+
* @param {GridRow} row the row from which the data comes
|
|
570
|
+
* @param {GridColumn} col the column from which the data comes
|
|
571
|
+
* @param {object} value the value for your massaging
|
|
572
|
+
* @returns {object} you must return the massaged value ready for exporting
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* <pre>
|
|
576
|
+
* gridOptions.exporterFieldCallback = function ( grid, row, col, value ) {
|
|
577
|
+
* if ( col.name === 'status' ) {
|
|
578
|
+
* value = decodeStatus( value );
|
|
579
|
+
* }
|
|
580
|
+
* return value;
|
|
581
|
+
* }
|
|
582
|
+
* </pre>
|
|
583
|
+
*/
|
|
584
|
+
gridOptions.exporterFieldCallback = gridOptions.exporterFieldCallback ? gridOptions.exporterFieldCallback : defaultExporterFieldCallback;
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* @ngdoc function
|
|
588
|
+
* @name exporterFieldFormatCallback
|
|
589
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
590
|
+
* @description A function to call for each field before exporting it. Allows
|
|
591
|
+
* general object to be return to modify the format of a cell in the case of
|
|
592
|
+
* excel exports
|
|
593
|
+
*
|
|
594
|
+
* The method is called once for each field exported, and provides the grid, the
|
|
595
|
+
* gridCol and the GridRow for you to use as context in massaging the data.
|
|
596
|
+
*
|
|
597
|
+
* @param {Grid} grid provides the grid in case you have need of it
|
|
598
|
+
* @param {GridRow} row the row from which the data comes
|
|
599
|
+
* @param {GridColumn} col the column from which the data comes
|
|
600
|
+
* @param {object} value the value for your massaging
|
|
601
|
+
* @returns {object} you must return the massaged value ready for exporting
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* <pre>
|
|
605
|
+
* gridOptions.exporterFieldCallback = function ( grid, row, col, value ) {
|
|
606
|
+
* if ( col.name === 'status' ) {
|
|
607
|
+
* value = decodeStatus( value );
|
|
608
|
+
* }
|
|
609
|
+
* return value;
|
|
610
|
+
* }
|
|
611
|
+
* </pre>
|
|
612
|
+
*/
|
|
613
|
+
gridOptions.exporterFieldFormatCallback = gridOptions.exporterFieldFormatCallback ? gridOptions.exporterFieldFormatCallback : function( grid, row, col, value ) { return null; };
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* @ngdoc function
|
|
617
|
+
* @name exporterExcelCustomFormatters
|
|
618
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
619
|
+
* @description A function to call to setup formatters and store on docDefinition.
|
|
620
|
+
*
|
|
621
|
+
* The method is called at the start and can setup all the formatters to export to excel
|
|
622
|
+
*
|
|
623
|
+
* @param {Grid} grid provides the grid in case you have need of it
|
|
624
|
+
* @param {Workbook} row the row from which the data comes
|
|
625
|
+
* @param {docDefinition} The docDefinition that will have styles as a object to store formatters
|
|
626
|
+
* @returns {docDefinition} Updated docDefinition with formatter styles
|
|
627
|
+
*
|
|
628
|
+
* @example
|
|
629
|
+
* <pre>
|
|
630
|
+
* gridOptions.exporterExcelCustomFormatters = function(grid, workbook, docDefinition) {
|
|
631
|
+
* const formatters = {};
|
|
632
|
+
* const stylesheet = workbook.getStyleSheet();
|
|
633
|
+
* const headerFormatDefn = {
|
|
634
|
+
* 'font': { 'size': 11, 'fontName': 'Calibri', 'bold': true },
|
|
635
|
+
* 'alignment': { 'wrapText': false }
|
|
636
|
+
* };
|
|
637
|
+
*
|
|
638
|
+
* formatters['header'] = headerFormatter;
|
|
639
|
+
* Object.assign(docDefinition.styles , formatters);
|
|
640
|
+
* grid.docDefinition = docDefinition;
|
|
641
|
+
* return docDefinition;
|
|
642
|
+
* }
|
|
643
|
+
* </pre>
|
|
644
|
+
*/
|
|
645
|
+
gridOptions.exporterExcelCustomFormatters = gridOptions.exporterExcelCustomFormatters ? gridOptions.exporterExcelCustomFormatters : function( grid, workbook, docDefinition ) { return docDefinition; };
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* @ngdoc function
|
|
649
|
+
* @name exporterExcelHeader
|
|
650
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
651
|
+
* @description A function to write formatted header data to sheet.
|
|
652
|
+
*
|
|
653
|
+
* The method is called to provide custom header building for Excel. This data comes before the grid header
|
|
654
|
+
*
|
|
655
|
+
* @param {grid} grid provides the grid in case you have need of it
|
|
656
|
+
* @param {Workbook} row the row from which the data comes
|
|
657
|
+
* @param {Sheet} the sheet to insert data
|
|
658
|
+
* @param {docDefinition} The docDefinition that will have styles as a object to store formatters
|
|
659
|
+
* @returns {docDefinition} Updated docDefinition with formatter styles
|
|
660
|
+
*
|
|
661
|
+
* @example
|
|
662
|
+
* <pre>
|
|
663
|
+
* gridOptions.exporterExcelCustomFormatters = function (grid, workbook, sheet, docDefinition) {
|
|
664
|
+
* const headerFormatter = docDefinition.styles['header'];
|
|
665
|
+
* let cols = [];
|
|
666
|
+
* // push data in A1 cell with metadata formatter
|
|
667
|
+
* cols.push({ value: 'Summary Report', metadata: {style: headerFormatter.id} });
|
|
668
|
+
* sheet.data.push(cols);
|
|
669
|
+
* }
|
|
670
|
+
* </pre>
|
|
671
|
+
*/
|
|
672
|
+
gridOptions.exporterExcelHeader = gridOptions.exporterExcelHeader ? gridOptions.exporterExcelHeader : function( grid, workbook, sheet, docDefinition ) { return null; };
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* @ngdoc object
|
|
677
|
+
* @name exporterColumnScaleFactor
|
|
678
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
679
|
+
* @description A scaling factor to divide the drawnwidth of a column to convert to target excel column
|
|
680
|
+
* format size
|
|
681
|
+
* @example
|
|
682
|
+
* In this example we add a number to divide the drawnwidth of a column to get the excel width.
|
|
683
|
+
* <br/>Defaults to 3.5
|
|
684
|
+
*/
|
|
685
|
+
gridOptions.exporterColumnScaleFactor = gridOptions.exporterColumnScaleFactor ? gridOptions.exporterColumnScaleFactor : 3.5;
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* @ngdoc object
|
|
689
|
+
* @name exporterFieldApplyFilters
|
|
690
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
691
|
+
* @description Defaults to false, which leads to filters being evaluated on export *
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* <pre>
|
|
695
|
+
* gridOptions.exporterFieldApplyFilters = true;
|
|
696
|
+
* </pre>
|
|
697
|
+
*/
|
|
698
|
+
gridOptions.exporterFieldApplyFilters = gridOptions.exporterFieldApplyFilters === true;
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* @ngdoc function
|
|
702
|
+
* @name exporterAllDataFn
|
|
703
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
704
|
+
* @description This promise is needed when exporting all rows,
|
|
705
|
+
* and the data need to be provided by server side. Default is null.
|
|
706
|
+
* @returns {Promise} a promise to load all data from server
|
|
707
|
+
*
|
|
708
|
+
* @example
|
|
709
|
+
* <pre>
|
|
710
|
+
* gridOptions.exporterAllDataFn = function () {
|
|
711
|
+
* return $http.get('/data/100.json')
|
|
712
|
+
* }
|
|
713
|
+
* </pre>
|
|
714
|
+
*/
|
|
715
|
+
gridOptions.exporterAllDataFn = gridOptions.exporterAllDataFn ? gridOptions.exporterAllDataFn : null;
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* @ngdoc function
|
|
719
|
+
* @name exporterAllDataPromise
|
|
720
|
+
* @propertyOf ui.grid.exporter.api:GridOptions
|
|
721
|
+
* @description DEPRECATED - exporterAllDataFn used to be
|
|
722
|
+
* called this, but it wasn't a promise, it was a function that returned
|
|
723
|
+
* a promise. Deprecated, but supported for backward compatibility, use
|
|
724
|
+
* exporterAllDataFn instead.
|
|
725
|
+
* @returns {Promise} a promise to load all data from server
|
|
726
|
+
*
|
|
727
|
+
* @example
|
|
728
|
+
* <pre>
|
|
729
|
+
* gridOptions.exporterAllDataFn = function () {
|
|
730
|
+
* return $http.get('/data/100.json')
|
|
731
|
+
* }
|
|
732
|
+
* </pre>
|
|
733
|
+
*/
|
|
734
|
+
if ( gridOptions.exporterAllDataFn === null && gridOptions.exporterAllDataPromise ) {
|
|
735
|
+
gridOptions.exporterAllDataFn = gridOptions.exporterAllDataPromise;
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* @ngdoc function
|
|
742
|
+
* @name addToMenu
|
|
743
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
744
|
+
* @description Adds export items to the grid menu,
|
|
745
|
+
* allowing the user to select export options
|
|
746
|
+
* @param {Grid} grid the grid from which data should be exported
|
|
747
|
+
*/
|
|
748
|
+
addToMenu: function ( grid ) {
|
|
749
|
+
grid.api.core.addToGridMenu( grid, [
|
|
750
|
+
{
|
|
751
|
+
title: i18nService.getSafeText('gridMenu.exporterAllAsCsv'),
|
|
752
|
+
action: function () {
|
|
753
|
+
grid.api.exporter.csvExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL );
|
|
754
|
+
},
|
|
755
|
+
shown: function() {
|
|
756
|
+
return grid.options.exporterMenuCsv && grid.options.exporterMenuAllData;
|
|
757
|
+
},
|
|
758
|
+
order: grid.options.exporterMenuItemOrder
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
title: i18nService.getSafeText('gridMenu.exporterVisibleAsCsv'),
|
|
762
|
+
action: function () {
|
|
763
|
+
grid.api.exporter.csvExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE );
|
|
764
|
+
},
|
|
765
|
+
shown: function() {
|
|
766
|
+
return grid.options.exporterMenuCsv && grid.options.exporterMenuVisibleData;
|
|
767
|
+
},
|
|
768
|
+
order: grid.options.exporterMenuItemOrder + 1
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
title: i18nService.getSafeText('gridMenu.exporterSelectedAsCsv'),
|
|
772
|
+
action: function () {
|
|
773
|
+
grid.api.exporter.csvExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE );
|
|
774
|
+
},
|
|
775
|
+
shown: function() {
|
|
776
|
+
return grid.options.exporterMenuCsv && grid.options.exporterMenuSelectedData &&
|
|
777
|
+
( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 );
|
|
778
|
+
},
|
|
779
|
+
order: grid.options.exporterMenuItemOrder + 2
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
title: i18nService.getSafeText('gridMenu.exporterAllAsPdf'),
|
|
783
|
+
action: function () {
|
|
784
|
+
grid.api.exporter.pdfExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL );
|
|
785
|
+
},
|
|
786
|
+
shown: function() {
|
|
787
|
+
return grid.options.exporterMenuPdf && grid.options.exporterMenuAllData;
|
|
788
|
+
},
|
|
789
|
+
order: grid.options.exporterMenuItemOrder + 3
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
title: i18nService.getSafeText('gridMenu.exporterVisibleAsPdf'),
|
|
793
|
+
action: function () {
|
|
794
|
+
grid.api.exporter.pdfExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE );
|
|
795
|
+
},
|
|
796
|
+
shown: function() {
|
|
797
|
+
return grid.options.exporterMenuPdf && grid.options.exporterMenuVisibleData;
|
|
798
|
+
},
|
|
799
|
+
order: grid.options.exporterMenuItemOrder + 4
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
title: i18nService.getSafeText('gridMenu.exporterSelectedAsPdf'),
|
|
803
|
+
action: function () {
|
|
804
|
+
grid.api.exporter.pdfExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE );
|
|
805
|
+
},
|
|
806
|
+
shown: function() {
|
|
807
|
+
return grid.options.exporterMenuPdf && grid.options.exporterMenuSelectedData &&
|
|
808
|
+
( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 );
|
|
809
|
+
},
|
|
810
|
+
order: grid.options.exporterMenuItemOrder + 5
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
title: i18nService.getSafeText('gridMenu.exporterAllAsExcel'),
|
|
814
|
+
action: function () {
|
|
815
|
+
grid.api.exporter.excelExport( uiGridExporterConstants.ALL, uiGridExporterConstants.ALL );
|
|
816
|
+
},
|
|
817
|
+
shown: function() {
|
|
818
|
+
return grid.options.exporterMenuExcel && grid.options.exporterMenuAllData;
|
|
819
|
+
},
|
|
820
|
+
order: grid.options.exporterMenuItemOrder + 6
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
title: i18nService.getSafeText('gridMenu.exporterVisibleAsExcel'),
|
|
824
|
+
action: function () {
|
|
825
|
+
grid.api.exporter.excelExport( uiGridExporterConstants.VISIBLE, uiGridExporterConstants.VISIBLE );
|
|
826
|
+
},
|
|
827
|
+
shown: function() {
|
|
828
|
+
return grid.options.exporterMenuExcel && grid.options.exporterMenuVisibleData;
|
|
829
|
+
},
|
|
830
|
+
order: grid.options.exporterMenuItemOrder + 7
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
title: i18nService.getSafeText('gridMenu.exporterSelectedAsExcel'),
|
|
834
|
+
action: function () {
|
|
835
|
+
grid.api.exporter.excelExport( uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE );
|
|
836
|
+
},
|
|
837
|
+
shown: function() {
|
|
838
|
+
return grid.options.exporterMenuExcel && grid.options.exporterMenuSelectedData &&
|
|
839
|
+
( grid.api.selection && grid.api.selection.getSelectedRows().length > 0 );
|
|
840
|
+
},
|
|
841
|
+
order: grid.options.exporterMenuItemOrder + 8
|
|
842
|
+
}
|
|
843
|
+
]);
|
|
844
|
+
},
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* @ngdoc function
|
|
849
|
+
* @name csvExport
|
|
850
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
851
|
+
* @description Exports rows from the grid in csv format,
|
|
852
|
+
* the data exported is selected based on the provided options
|
|
853
|
+
* @param {Grid} grid the grid from which data should be exported
|
|
854
|
+
* @param {string} rowTypes which rows to export, valid values are
|
|
855
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
856
|
+
* uiGridExporterConstants.SELECTED
|
|
857
|
+
* @param {string} colTypes which columns to export, valid values are
|
|
858
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
859
|
+
* uiGridExporterConstants.SELECTED
|
|
860
|
+
*/
|
|
861
|
+
csvExport: function (grid, rowTypes, colTypes) {
|
|
862
|
+
var self = this;
|
|
863
|
+
self.type = 'csv';
|
|
864
|
+
this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function() {
|
|
865
|
+
var exportColumnHeaders = grid.options.showHeader ? self.getColumnHeaders(grid, colTypes) : [];
|
|
866
|
+
var exportData = self.getData(grid, rowTypes, colTypes);
|
|
867
|
+
var csvContent = self.formatAsCsv(exportColumnHeaders, exportData, grid.options.exporterCsvColumnSeparator);
|
|
868
|
+
|
|
869
|
+
var fileName = angular.isFunction(grid.options.exporterCsvFilename) ? grid.options.exporterCsvFilename(grid, rowTypes, colTypes) : grid.options.exporterCsvFilename;
|
|
870
|
+
self.downloadFile(fileName, csvContent, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility, grid.options.exporterIsExcelCompatible);
|
|
871
|
+
});
|
|
872
|
+
},
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* @ngdoc function
|
|
876
|
+
* @name loadAllDataIfNeeded
|
|
877
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
878
|
+
* @description When using server side pagination, use exporterAllDataFn to
|
|
879
|
+
* load all data before continuing processing.
|
|
880
|
+
* When using client side pagination, return a resolved promise so processing
|
|
881
|
+
* continues immediately
|
|
882
|
+
* @param {Grid} grid the grid from which data should be exported
|
|
883
|
+
* @param {string} rowTypes which rows to export, valid values are
|
|
884
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
885
|
+
* uiGridExporterConstants.SELECTED
|
|
886
|
+
* @param {string} colTypes which columns to export, valid values are
|
|
887
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
888
|
+
* uiGridExporterConstants.SELECTED
|
|
889
|
+
*/
|
|
890
|
+
loadAllDataIfNeeded: function (grid, rowTypes, colTypes) {
|
|
891
|
+
if ( rowTypes === uiGridExporterConstants.ALL && grid.rows.length !== grid.options.totalItems && grid.options.exporterAllDataFn) {
|
|
892
|
+
return grid.options.exporterAllDataFn()
|
|
893
|
+
.then(function(allData) {
|
|
894
|
+
grid.modifyRows(allData);
|
|
895
|
+
});
|
|
896
|
+
} else {
|
|
897
|
+
var deferred = $q.defer();
|
|
898
|
+
deferred.resolve();
|
|
899
|
+
return deferred.promise;
|
|
900
|
+
}
|
|
901
|
+
},
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* @ngdoc property
|
|
905
|
+
* @propertyOf ui.grid.exporter.api:ColumnDef
|
|
906
|
+
* @name exporterSuppressExport
|
|
907
|
+
* @description Suppresses export for this column. Used by selection and expandable.
|
|
908
|
+
*/
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* @ngdoc function
|
|
912
|
+
* @name getColumnHeaders
|
|
913
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
914
|
+
* @description Gets the column headers from the grid to use
|
|
915
|
+
* as a title row for the exported file, all headers have
|
|
916
|
+
* headerCellFilters applied as appropriate.
|
|
917
|
+
*
|
|
918
|
+
* Column headers are an array of objects, each object has
|
|
919
|
+
* name, displayName, width and align attributes. Only name is
|
|
920
|
+
* used for csv, all attributes are used for pdf.
|
|
921
|
+
*
|
|
922
|
+
* @param {Grid} grid the grid from which data should be exported
|
|
923
|
+
* @param {string} colTypes which columns to export, valid values are
|
|
924
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
925
|
+
* uiGridExporterConstants.SELECTED
|
|
926
|
+
*/
|
|
927
|
+
getColumnHeaders: function (grid, colTypes) {
|
|
928
|
+
var headers = [],
|
|
929
|
+
columns;
|
|
930
|
+
|
|
931
|
+
if ( colTypes === uiGridExporterConstants.ALL ) {
|
|
932
|
+
columns = grid.columns;
|
|
933
|
+
} else {
|
|
934
|
+
var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [],
|
|
935
|
+
bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [],
|
|
936
|
+
rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [];
|
|
937
|
+
|
|
938
|
+
columns = leftColumns.concat(bodyColumns, rightColumns);
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
columns.forEach( function( gridCol ) {
|
|
942
|
+
// $$hashKey check since when grouping and sorting pragmatically this ends up in export. Filtering it out
|
|
943
|
+
if ( gridCol.colDef.exporterSuppressExport !== true && gridCol.field !== '$$hashKey' &&
|
|
944
|
+
grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ) {
|
|
945
|
+
var headerEntry = {
|
|
946
|
+
name: gridCol.field,
|
|
947
|
+
displayName: getDisplayName(grid, gridCol),
|
|
948
|
+
width: gridCol.drawnWidth ? gridCol.drawnWidth : gridCol.width,
|
|
949
|
+
align: gridCol.colDef.align ? gridCol.colDef.align : (gridCol.colDef.type === 'number' ? 'right' : 'left')
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
headers.push(headerEntry);
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
return headers;
|
|
957
|
+
},
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* @ngdoc property
|
|
961
|
+
* @propertyOf ui.grid.exporter.api:ColumnDef
|
|
962
|
+
* @name exporterPdfAlign
|
|
963
|
+
* @description the alignment you'd like for this specific column when
|
|
964
|
+
* exported into a pdf. Can be 'left', 'right', 'center' or any other
|
|
965
|
+
* valid pdfMake alignment option.
|
|
966
|
+
*/
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* @ngdoc object
|
|
970
|
+
* @name ui.grid.exporter.api:GridRow
|
|
971
|
+
* @description GridRow settings for exporter
|
|
972
|
+
*/
|
|
973
|
+
|
|
974
|
+
/**
|
|
975
|
+
* @ngdoc object
|
|
976
|
+
* @name exporterEnableExporting
|
|
977
|
+
* @propertyOf ui.grid.exporter.api:GridRow
|
|
978
|
+
* @description If set to false, then don't export this row, notwithstanding visible or
|
|
979
|
+
* other settings
|
|
980
|
+
* <br/>Defaults to true
|
|
981
|
+
*/
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* @ngdoc function
|
|
985
|
+
* @name getRowsFromNode
|
|
986
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
987
|
+
* @description Gets rows from a node. If the node is grouped it will
|
|
988
|
+
* recurse down into the children to get to the raw data element
|
|
989
|
+
* which is a row without children (a leaf).
|
|
990
|
+
* @param {Node} aNode the tree node on the grid
|
|
991
|
+
* @returns {Array} an array with all child nodes from aNode
|
|
992
|
+
*/
|
|
993
|
+
getRowsFromNode: function(aNode) {
|
|
994
|
+
var rows = [];
|
|
995
|
+
|
|
996
|
+
// Push parent node if it is not undefined and has values other than 'children'
|
|
997
|
+
var nodeKeys = aNode ? Object.keys(aNode) : ['children'];
|
|
998
|
+
if (nodeKeys.length > 1 || nodeKeys[0] != 'children') {
|
|
999
|
+
rows.push(aNode);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
if (aNode && aNode.children && aNode.children.length > 0) {
|
|
1003
|
+
for (var i = 0; i < aNode.children.length; i++) {
|
|
1004
|
+
rows = rows.concat(this.getRowsFromNode(aNode.children[i]));
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
return rows;
|
|
1008
|
+
},
|
|
1009
|
+
/**
|
|
1010
|
+
* @ngdoc function
|
|
1011
|
+
* @name getDataSorted
|
|
1012
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1013
|
+
* @description Gets rows from a node. If the node is grouped it will
|
|
1014
|
+
* recurse down into the children to get to the raw data element
|
|
1015
|
+
* which is a row without children (a leaf). If the grid is not
|
|
1016
|
+
* grouped this will return just the raw rows
|
|
1017
|
+
* @param {Grid} grid the grid from which data should be exported
|
|
1018
|
+
* @returns {Array} an array of leaf nodes
|
|
1019
|
+
*/
|
|
1020
|
+
getDataSorted: function (grid) {
|
|
1021
|
+
if (!grid.treeBase || grid.treeBase.numberLevels === 0) {
|
|
1022
|
+
return grid.rows;
|
|
1023
|
+
}
|
|
1024
|
+
var rows = [];
|
|
1025
|
+
|
|
1026
|
+
for (var i = 0; i< grid.treeBase.tree.length; i++) {
|
|
1027
|
+
var nodeRows = this.getRowsFromNode(grid.treeBase.tree[i]);
|
|
1028
|
+
|
|
1029
|
+
for (var j = 0; j<nodeRows.length; j++) {
|
|
1030
|
+
rows.push(nodeRows[j].row);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return rows;
|
|
1034
|
+
},
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* @ngdoc function
|
|
1038
|
+
* @name getData
|
|
1039
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1040
|
+
* @description Gets data from the grid based on the provided options,
|
|
1041
|
+
* all cells have cellFilters applied as appropriate. Any rows marked
|
|
1042
|
+
* `exporterEnableExporting: false` will not be exported
|
|
1043
|
+
* @param {Grid} grid the grid from which data should be exported
|
|
1044
|
+
* @param {string} rowTypes which rows to export, valid values are
|
|
1045
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
1046
|
+
* uiGridExporterConstants.SELECTED
|
|
1047
|
+
* @param {string} colTypes which columns to export, valid values are
|
|
1048
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
1049
|
+
* uiGridExporterConstants.SELECTED
|
|
1050
|
+
* @param {boolean} applyCellFilters whether or not to get the display value or the raw value of the data
|
|
1051
|
+
*/
|
|
1052
|
+
getData: function (grid, rowTypes, colTypes, applyCellFilters) {
|
|
1053
|
+
var data = [],
|
|
1054
|
+
rows,
|
|
1055
|
+
columns;
|
|
1056
|
+
|
|
1057
|
+
switch ( rowTypes ) {
|
|
1058
|
+
case uiGridExporterConstants.ALL:
|
|
1059
|
+
rows = this.getDataSorted(grid, rowTypes, colTypes, applyCellFilters);
|
|
1060
|
+
break;
|
|
1061
|
+
case uiGridExporterConstants.VISIBLE:
|
|
1062
|
+
rows = grid.getVisibleRows();
|
|
1063
|
+
break;
|
|
1064
|
+
case uiGridExporterConstants.SELECTED:
|
|
1065
|
+
if ( grid.api.selection ) {
|
|
1066
|
+
rows = grid.api.selection.getSelectedGridRows();
|
|
1067
|
+
} else {
|
|
1068
|
+
gridUtil.logError('selection feature must be enabled to allow selected rows to be exported');
|
|
1069
|
+
}
|
|
1070
|
+
break;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
if ( colTypes === uiGridExporterConstants.ALL ) {
|
|
1074
|
+
columns = grid.columns;
|
|
1075
|
+
} else {
|
|
1076
|
+
var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [];
|
|
1077
|
+
var bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [];
|
|
1078
|
+
var rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ) { return column.visible; } ) : [];
|
|
1079
|
+
|
|
1080
|
+
columns = leftColumns.concat(bodyColumns, rightColumns);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
rows.forEach(function( row ) {
|
|
1084
|
+
if (row.exporterEnableExporting !== false) {
|
|
1085
|
+
var extractedRow = [];
|
|
1086
|
+
|
|
1087
|
+
columns.forEach( function( gridCol ) {
|
|
1088
|
+
// $$hashKey check since when grouping and sorting programmatically this ends up in export. Filtering it out
|
|
1089
|
+
if ( (gridCol.visible || colTypes === uiGridExporterConstants.ALL ) &&
|
|
1090
|
+
gridCol.colDef.exporterSuppressExport !== true && gridCol.field !== '$$hashKey' &&
|
|
1091
|
+
grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ) {
|
|
1092
|
+
var cellValue = applyCellFilters ? grid.getCellDisplayValue( row, gridCol ) : grid.getCellValue( row, gridCol ),
|
|
1093
|
+
extractedField = { value: grid.options.exporterFieldCallback( grid, row, gridCol, cellValue, service.type ) },
|
|
1094
|
+
extension = grid.options.exporterFieldFormatCallback( grid, row, gridCol, cellValue, service.type );
|
|
1095
|
+
|
|
1096
|
+
if (extension) {
|
|
1097
|
+
Object.assign(extractedField, extension);
|
|
1098
|
+
}
|
|
1099
|
+
if ( gridCol.colDef.exporterPdfAlign ) {
|
|
1100
|
+
extractedField.alignment = gridCol.colDef.exporterPdfAlign;
|
|
1101
|
+
}
|
|
1102
|
+
extractedRow.push(extractedField);
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
|
|
1106
|
+
data.push(extractedRow);
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
|
|
1110
|
+
return data;
|
|
1111
|
+
},
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* @ngdoc function
|
|
1116
|
+
* @name formatAsCsv
|
|
1117
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1118
|
+
* @description Formats the column headers and data as a CSV,
|
|
1119
|
+
* and sends that data to the user
|
|
1120
|
+
* @param {array} exportColumnHeaders an array of column headers,
|
|
1121
|
+
* where each header is an object with name, width and maybe alignment
|
|
1122
|
+
* @param {array} exportData an array of rows, where each row is
|
|
1123
|
+
* an array of column data
|
|
1124
|
+
* @param {string} separator a string that represents the separator to be used in the csv file
|
|
1125
|
+
* @returns {string} csv the formatted csv as a string
|
|
1126
|
+
*/
|
|
1127
|
+
formatAsCsv: function (exportColumnHeaders, exportData, separator) {
|
|
1128
|
+
var self = this,
|
|
1129
|
+
bareHeaders = exportColumnHeaders.map(function(header) { return { value: header.displayName };}),
|
|
1130
|
+
csv = bareHeaders.length > 0 ? (self.formatRowAsCsv(this, separator)(bareHeaders) + '\n') : '';
|
|
1131
|
+
|
|
1132
|
+
csv += exportData.map(this.formatRowAsCsv(this, separator)).join('\n');
|
|
1133
|
+
|
|
1134
|
+
return csv;
|
|
1135
|
+
},
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* @ngdoc function
|
|
1139
|
+
* @name formatRowAsCsv
|
|
1140
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1141
|
+
* @description Renders a single field as a csv field, including
|
|
1142
|
+
* quotes around the value
|
|
1143
|
+
* @param {exporterService} exporter pass in exporter
|
|
1144
|
+
* @param {string} separator the string to be used to join the row data
|
|
1145
|
+
* @returns {function} A function that returns a csv-ified version of the row
|
|
1146
|
+
*/
|
|
1147
|
+
formatRowAsCsv: function (exporter, separator) {
|
|
1148
|
+
return function (row) {
|
|
1149
|
+
return row.map(exporter.formatFieldAsCsv).join(separator);
|
|
1150
|
+
};
|
|
1151
|
+
},
|
|
1152
|
+
|
|
1153
|
+
/**
|
|
1154
|
+
* @ngdoc function
|
|
1155
|
+
* @name formatFieldAsCsv
|
|
1156
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1157
|
+
* @description Renders a single field as a csv field, including
|
|
1158
|
+
* quotes around the value
|
|
1159
|
+
* @param {field} field the field to be turned into a csv string,
|
|
1160
|
+
* may be of any type
|
|
1161
|
+
* @returns {string} a csv-ified version of the field
|
|
1162
|
+
*/
|
|
1163
|
+
formatFieldAsCsv: function (field) {
|
|
1164
|
+
if (field.value == null) { // we want to catch anything null-ish, hence just == not ===
|
|
1165
|
+
return '';
|
|
1166
|
+
}
|
|
1167
|
+
if (typeof(field.value) === 'number') {
|
|
1168
|
+
return field.value;
|
|
1169
|
+
}
|
|
1170
|
+
if (typeof(field.value) === 'boolean') {
|
|
1171
|
+
return (field.value ? 'TRUE' : 'FALSE') ;
|
|
1172
|
+
}
|
|
1173
|
+
if (typeof(field.value) === 'string') {
|
|
1174
|
+
return '"' + field.value.replace(/"/g,'""') + '"';
|
|
1175
|
+
}
|
|
1176
|
+
if (typeof(field.value) === 'object' && !(field.value instanceof Date)) {
|
|
1177
|
+
return '"' + JSON.stringify(field.value).replace(/"/g,'""') + '"';
|
|
1178
|
+
}
|
|
1179
|
+
// if field type is date, numberStr
|
|
1180
|
+
return JSON.stringify(field.value);
|
|
1181
|
+
},
|
|
1182
|
+
|
|
1183
|
+
/**
|
|
1184
|
+
* @ngdoc function
|
|
1185
|
+
* @name isIE
|
|
1186
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1187
|
+
* @description Checks whether current browser is IE and returns it's version if it is
|
|
1188
|
+
*/
|
|
1189
|
+
isIE: function () {
|
|
1190
|
+
var match = navigator.userAgent.search(/(?:Edge|MSIE|Trident\/.*; rv:)/);
|
|
1191
|
+
var isIE = false;
|
|
1192
|
+
|
|
1193
|
+
if (match !== -1) {
|
|
1194
|
+
isIE = true;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
return isIE;
|
|
1198
|
+
},
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* @ngdoc function
|
|
1203
|
+
* @name downloadFile
|
|
1204
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1205
|
+
* @description Triggers download of a csv file. Logic provided
|
|
1206
|
+
* by @cssensei (from his colleagues at https://github.com/ifeelgoods) in issue #2391
|
|
1207
|
+
* @param {string} fileName the filename we'd like our file to be
|
|
1208
|
+
* given
|
|
1209
|
+
* @param {string} csvContent the csv content that we'd like to
|
|
1210
|
+
* download as a file
|
|
1211
|
+
* @param {string} columnSeparator The separator to be used by the columns
|
|
1212
|
+
* @param {boolean} exporterOlderExcelCompatibility whether or not we put a utf-16 BOM on the from (\uFEFF)
|
|
1213
|
+
* @param {boolean} exporterIsExcelCompatible whether or not we add separator header ('sep=X')
|
|
1214
|
+
*/
|
|
1215
|
+
downloadFile: function (fileName, csvContent, columnSeparator, exporterOlderExcelCompatibility, exporterIsExcelCompatible) {
|
|
1216
|
+
var D = document,
|
|
1217
|
+
a = D.createElement('a'),
|
|
1218
|
+
strMimeType = 'application/octet-stream;charset=utf-8',
|
|
1219
|
+
rawFile,
|
|
1220
|
+
ieVersion = this.isIE();
|
|
1221
|
+
|
|
1222
|
+
if (exporterIsExcelCompatible) {
|
|
1223
|
+
csvContent = 'sep=' + columnSeparator + '\r\n' + csvContent;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
// IE10+
|
|
1227
|
+
if (navigator.msSaveBlob) {
|
|
1228
|
+
return navigator.msSaveOrOpenBlob(
|
|
1229
|
+
new Blob(
|
|
1230
|
+
[exporterOlderExcelCompatibility ? "\uFEFF" : '', csvContent],
|
|
1231
|
+
{ type: strMimeType } ),
|
|
1232
|
+
fileName
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
if (ieVersion) {
|
|
1237
|
+
var frame = D.createElement('iframe');
|
|
1238
|
+
|
|
1239
|
+
document.body.appendChild(frame);
|
|
1240
|
+
|
|
1241
|
+
frame.contentWindow.document.open('text/html', 'replace');
|
|
1242
|
+
frame.contentWindow.document.write(csvContent);
|
|
1243
|
+
frame.contentWindow.document.close();
|
|
1244
|
+
frame.contentWindow.focus();
|
|
1245
|
+
frame.contentWindow.document.execCommand('SaveAs', true, fileName);
|
|
1246
|
+
|
|
1247
|
+
document.body.removeChild(frame);
|
|
1248
|
+
return true;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
// html5 A[download]
|
|
1252
|
+
if ('download' in a) {
|
|
1253
|
+
var blob = new Blob(
|
|
1254
|
+
[exporterOlderExcelCompatibility ? "\uFEFF" : '', csvContent],
|
|
1255
|
+
{ type: strMimeType }
|
|
1256
|
+
);
|
|
1257
|
+
rawFile = URL.createObjectURL(blob);
|
|
1258
|
+
a.setAttribute('download', fileName);
|
|
1259
|
+
} else {
|
|
1260
|
+
rawFile = 'data: ' + strMimeType + ',' + encodeURIComponent(csvContent);
|
|
1261
|
+
a.setAttribute('target', '_blank');
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
a.href = rawFile;
|
|
1265
|
+
a.setAttribute('style', 'display:none;');
|
|
1266
|
+
D.body.appendChild(a);
|
|
1267
|
+
setTimeout(function() {
|
|
1268
|
+
if (a.click) {
|
|
1269
|
+
a.click();
|
|
1270
|
+
// Workaround for Safari 5
|
|
1271
|
+
} else if (document.createEvent) {
|
|
1272
|
+
var eventObj = document.createEvent('MouseEvents');
|
|
1273
|
+
eventObj.initEvent('click', true, true);
|
|
1274
|
+
a.dispatchEvent(eventObj);
|
|
1275
|
+
}
|
|
1276
|
+
D.body.removeChild(a);
|
|
1277
|
+
|
|
1278
|
+
}, this.delay);
|
|
1279
|
+
},
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* @ngdoc function
|
|
1283
|
+
* @name pdfExport
|
|
1284
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1285
|
+
* @description Exports rows from the grid in pdf format,
|
|
1286
|
+
* the data exported is selected based on the provided options.
|
|
1287
|
+
* Note that this function has a dependency on pdfMake, which must
|
|
1288
|
+
* be installed. The resulting pdf opens in a new
|
|
1289
|
+
* browser window.
|
|
1290
|
+
* @param {Grid} grid the grid from which data should be exported
|
|
1291
|
+
* @param {string} rowTypes which rows to export, valid values are
|
|
1292
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
1293
|
+
* uiGridExporterConstants.SELECTED
|
|
1294
|
+
* @param {string} colTypes which columns to export, valid values are
|
|
1295
|
+
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
|
|
1296
|
+
* uiGridExporterConstants.SELECTED
|
|
1297
|
+
*/
|
|
1298
|
+
pdfExport: function (grid, rowTypes, colTypes) {
|
|
1299
|
+
var self = this;
|
|
1300
|
+
self.type = 'pdf';
|
|
1301
|
+
this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function () {
|
|
1302
|
+
var exportColumnHeaders = self.getColumnHeaders(grid, colTypes),
|
|
1303
|
+
exportData = self.getData(grid, rowTypes, colTypes),
|
|
1304
|
+
docDefinition = self.prepareAsPdf(grid, exportColumnHeaders, exportData);
|
|
1305
|
+
|
|
1306
|
+
if (self.isIE() || navigator.appVersion.indexOf('Edge') !== -1) {
|
|
1307
|
+
var fileName = angular.isFunction(grid.options.exporterPdfFilename) ? grid.options.exporterPdfFilename(grid, rowTypes, colTypes) : grid.options.exporterPdfFilename;
|
|
1308
|
+
self.downloadPDF(fileName, docDefinition);
|
|
1309
|
+
} else {
|
|
1310
|
+
pdfMake.createPdf(docDefinition).open();
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
},
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
/**
|
|
1317
|
+
* @ngdoc function
|
|
1318
|
+
* @name downloadPdf
|
|
1319
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1320
|
+
* @description Generates and retrieves the pdf as a blob, then downloads
|
|
1321
|
+
* it as a file. Only used in IE, in all other browsers we use the native
|
|
1322
|
+
* pdfMake.open function to just open the PDF
|
|
1323
|
+
* @param {string} fileName the filename to give to the pdf, can be set
|
|
1324
|
+
* through exporterPdfFilename
|
|
1325
|
+
* @param {object} docDefinition a pdf docDefinition that we can generate
|
|
1326
|
+
* and get a blob from
|
|
1327
|
+
*/
|
|
1328
|
+
downloadPDF: function (fileName, docDefinition) {
|
|
1329
|
+
var D = document,
|
|
1330
|
+
a = D.createElement('a'),
|
|
1331
|
+
ieVersion;
|
|
1332
|
+
|
|
1333
|
+
ieVersion = this.isIE(); // This is now a boolean value
|
|
1334
|
+
var doc = pdfMake.createPdf(docDefinition);
|
|
1335
|
+
var blob;
|
|
1336
|
+
|
|
1337
|
+
doc.getBuffer( function (buffer) {
|
|
1338
|
+
blob = new Blob([buffer]);
|
|
1339
|
+
|
|
1340
|
+
// IE10+
|
|
1341
|
+
if (navigator.msSaveBlob) {
|
|
1342
|
+
return navigator.msSaveBlob(
|
|
1343
|
+
blob, fileName
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
// Previously: && ieVersion < 10
|
|
1348
|
+
// ieVersion now returns a boolean for the
|
|
1349
|
+
// sake of sanity. We just check `msSaveBlob` first.
|
|
1350
|
+
if (ieVersion) {
|
|
1351
|
+
var frame = D.createElement('iframe');
|
|
1352
|
+
document.body.appendChild(frame);
|
|
1353
|
+
|
|
1354
|
+
frame.contentWindow.document.open('text/html', 'replace');
|
|
1355
|
+
frame.contentWindow.document.write(blob);
|
|
1356
|
+
frame.contentWindow.document.close();
|
|
1357
|
+
frame.contentWindow.focus();
|
|
1358
|
+
frame.contentWindow.document.execCommand('SaveAs', true, fileName);
|
|
1359
|
+
|
|
1360
|
+
document.body.removeChild(frame);
|
|
1361
|
+
return true;
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
},
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
/**
|
|
1368
|
+
* @ngdoc function
|
|
1369
|
+
* @name renderAsPdf
|
|
1370
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1371
|
+
* @description Renders the data into a pdf, and opens that pdf.
|
|
1372
|
+
*
|
|
1373
|
+
* @param {Grid} grid the grid from which data should be exported
|
|
1374
|
+
* @param {array} exportColumnHeaders an array of column headers,
|
|
1375
|
+
* where each header is an object with name, width and maybe alignment
|
|
1376
|
+
* @param {array} exportData an array of rows, where each row is
|
|
1377
|
+
* an array of column data
|
|
1378
|
+
* @returns {object} a pdfMake format document definition, ready
|
|
1379
|
+
* for generation
|
|
1380
|
+
*/
|
|
1381
|
+
prepareAsPdf: function(grid, exportColumnHeaders, exportData) {
|
|
1382
|
+
var headerWidths = this.calculatePdfHeaderWidths( grid, exportColumnHeaders );
|
|
1383
|
+
|
|
1384
|
+
var headerColumns = exportColumnHeaders.map( function( header ) {
|
|
1385
|
+
return { text: header.displayName, style: 'tableHeader' };
|
|
1386
|
+
});
|
|
1387
|
+
|
|
1388
|
+
var stringData = exportData.map(this.formatRowAsPdf(this));
|
|
1389
|
+
|
|
1390
|
+
var allData = [headerColumns].concat(stringData);
|
|
1391
|
+
|
|
1392
|
+
var docDefinition = {
|
|
1393
|
+
pageOrientation: grid.options.exporterPdfOrientation,
|
|
1394
|
+
pageSize: grid.options.exporterPdfPageSize,
|
|
1395
|
+
content: [{
|
|
1396
|
+
style: 'tableStyle',
|
|
1397
|
+
table: {
|
|
1398
|
+
headerRows: 1,
|
|
1399
|
+
widths: headerWidths,
|
|
1400
|
+
body: allData
|
|
1401
|
+
}
|
|
1402
|
+
}],
|
|
1403
|
+
styles: {
|
|
1404
|
+
tableStyle: grid.options.exporterPdfTableStyle,
|
|
1405
|
+
tableHeader: grid.options.exporterPdfTableHeaderStyle
|
|
1406
|
+
},
|
|
1407
|
+
defaultStyle: grid.options.exporterPdfDefaultStyle
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
if ( grid.options.exporterPdfLayout ) {
|
|
1411
|
+
docDefinition.layout = grid.options.exporterPdfLayout;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
if ( grid.options.exporterPdfHeader ) {
|
|
1415
|
+
docDefinition.header = grid.options.exporterPdfHeader;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
if ( grid.options.exporterPdfFooter ) {
|
|
1419
|
+
docDefinition.footer = grid.options.exporterPdfFooter;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
if ( grid.options.exporterPdfCustomFormatter ) {
|
|
1423
|
+
docDefinition = grid.options.exporterPdfCustomFormatter( docDefinition );
|
|
1424
|
+
}
|
|
1425
|
+
return docDefinition;
|
|
1426
|
+
|
|
1427
|
+
},
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
/**
|
|
1431
|
+
* @ngdoc function
|
|
1432
|
+
* @name calculatePdfHeaderWidths
|
|
1433
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1434
|
+
* @description Determines the column widths base on the
|
|
1435
|
+
* widths we got from the grid. If the column is drawn
|
|
1436
|
+
* then we have a drawnWidth. If the column is not visible
|
|
1437
|
+
* then we have '*', 'x%' or a width. When columns are
|
|
1438
|
+
* not visible they don't contribute to the overall gridWidth,
|
|
1439
|
+
* so we need to adjust to allow for extra columns
|
|
1440
|
+
*
|
|
1441
|
+
* Our basic heuristic is to take the current gridWidth, plus
|
|
1442
|
+
* numeric columns and call this the base gridwidth.
|
|
1443
|
+
*
|
|
1444
|
+
* To that we add 100 for any '*' column, and x% of the base gridWidth
|
|
1445
|
+
* for any column that is a %
|
|
1446
|
+
*
|
|
1447
|
+
* @param {Grid} grid the grid from which data should be exported
|
|
1448
|
+
* @param {array} exportHeaders array of header information
|
|
1449
|
+
* @returns {object} an array of header widths
|
|
1450
|
+
*/
|
|
1451
|
+
calculatePdfHeaderWidths: function ( grid, exportHeaders ) {
|
|
1452
|
+
var baseGridWidth = 0;
|
|
1453
|
+
|
|
1454
|
+
exportHeaders.forEach(function(value) {
|
|
1455
|
+
if (typeof(value.width) === 'number') {
|
|
1456
|
+
baseGridWidth += value.width;
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
|
|
1460
|
+
var extraColumns = 0;
|
|
1461
|
+
|
|
1462
|
+
exportHeaders.forEach(function(value) {
|
|
1463
|
+
if (value.width === '*') {
|
|
1464
|
+
extraColumns += 100;
|
|
1465
|
+
}
|
|
1466
|
+
if (typeof(value.width) === 'string' && value.width.match(/(\d)*%/)) {
|
|
1467
|
+
var percent = parseInt(value.width.match(/(\d)*%/)[0]);
|
|
1468
|
+
|
|
1469
|
+
value.width = baseGridWidth * percent / 100;
|
|
1470
|
+
extraColumns += value.width;
|
|
1471
|
+
}
|
|
1472
|
+
});
|
|
1473
|
+
|
|
1474
|
+
var gridWidth = baseGridWidth + extraColumns;
|
|
1475
|
+
|
|
1476
|
+
return exportHeaders.map(function( header ) {
|
|
1477
|
+
return header.width === '*' ? header.width : header.width * grid.options.exporterPdfMaxGridWidth / gridWidth;
|
|
1478
|
+
});
|
|
1479
|
+
},
|
|
1480
|
+
|
|
1481
|
+
/**
|
|
1482
|
+
* @ngdoc function
|
|
1483
|
+
* @name formatRowAsPdf
|
|
1484
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1485
|
+
* @description Renders a row in a format consumable by PDF,
|
|
1486
|
+
* mainly meaning casting everything to a string
|
|
1487
|
+
* @param {exporterService} exporter pass in exporter
|
|
1488
|
+
* @param {array} row the row to be turned into a csv string
|
|
1489
|
+
* @returns {string} a csv-ified version of the row
|
|
1490
|
+
*/
|
|
1491
|
+
formatRowAsPdf: function ( exporter ) {
|
|
1492
|
+
return function( row ) {
|
|
1493
|
+
return row.map(exporter.formatFieldAsPdfString);
|
|
1494
|
+
};
|
|
1495
|
+
},
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
/**
|
|
1499
|
+
* @ngdoc function
|
|
1500
|
+
* @name formatFieldAsCsv
|
|
1501
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1502
|
+
* @description Renders a single field as a pdf-able field, which
|
|
1503
|
+
* is different from a csv field only in that strings don't have quotes
|
|
1504
|
+
* around them
|
|
1505
|
+
* @param {field} field the field to be turned into a pdf string,
|
|
1506
|
+
* may be of any type
|
|
1507
|
+
* @returns {string} a string-ified version of the field
|
|
1508
|
+
*/
|
|
1509
|
+
formatFieldAsPdfString: function (field) {
|
|
1510
|
+
var returnVal;
|
|
1511
|
+
|
|
1512
|
+
if (field.value == null) { // we want to catch anything null-ish, hence just == not ===
|
|
1513
|
+
returnVal = '';
|
|
1514
|
+
} else if (typeof(field.value) === 'number') {
|
|
1515
|
+
returnVal = field.value.toString();
|
|
1516
|
+
} else if (typeof(field.value) === 'boolean') {
|
|
1517
|
+
returnVal = (field.value ? 'TRUE' : 'FALSE') ;
|
|
1518
|
+
} else if (typeof(field.value) === 'string') {
|
|
1519
|
+
returnVal = field.value.replace(/"/g,'""');
|
|
1520
|
+
} else if (field.value instanceof Date) {
|
|
1521
|
+
returnVal = JSON.stringify(field.value).replace(/^"/,'').replace(/"$/,'');
|
|
1522
|
+
} else if (typeof(field.value) === 'object') {
|
|
1523
|
+
returnVal = field.value;
|
|
1524
|
+
} else {
|
|
1525
|
+
returnVal = JSON.stringify(field.value).replace(/^"/,'').replace(/"$/,'');
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
if (field.alignment && typeof(field.alignment) === 'string' ) {
|
|
1529
|
+
returnVal = { text: returnVal, alignment: field.alignment };
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
return returnVal;
|
|
1533
|
+
},
|
|
1534
|
+
|
|
1535
|
+
/**
|
|
1536
|
+
* @ngdoc function
|
|
1537
|
+
* @name formatAsExcel
|
|
1538
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1539
|
+
* @description Formats the column headers and data as a excel,
|
|
1540
|
+
* and sends that data to the user
|
|
1541
|
+
* @param {array} exportColumnHeaders an array of column headers,
|
|
1542
|
+
* where each header is an object with name, width and maybe alignment
|
|
1543
|
+
* @param {array} exportData an array of rows, where each row is
|
|
1544
|
+
* an array of column data
|
|
1545
|
+
* @param {string} separator a string that represents the separator to be used in the csv file
|
|
1546
|
+
* @returns {string} csv the formatted excel as a string
|
|
1547
|
+
*/
|
|
1548
|
+
formatAsExcel: function (exportColumnHeaders, exportData, workbook, sheet, docDefinition) {
|
|
1549
|
+
var bareHeaders = exportColumnHeaders.map(function(header) {return { value: header.displayName };});
|
|
1550
|
+
|
|
1551
|
+
var sheetData = [];
|
|
1552
|
+
var headerData = [];
|
|
1553
|
+
for (var i = 0; i < bareHeaders.length; i++) {
|
|
1554
|
+
// TODO - probably need callback to determine header value and header styling
|
|
1555
|
+
var exportStyle = 'header';
|
|
1556
|
+
switch (exportColumnHeaders[i].align) {
|
|
1557
|
+
case 'center':
|
|
1558
|
+
exportStyle = 'headerCenter';
|
|
1559
|
+
break;
|
|
1560
|
+
case 'right':
|
|
1561
|
+
exportStyle = 'headerRight';
|
|
1562
|
+
break;
|
|
1563
|
+
}
|
|
1564
|
+
var metadata = (docDefinition.styles && docDefinition.styles[exportStyle]) ? {style: docDefinition.styles[exportStyle].id} : null;
|
|
1565
|
+
headerData.push({value: bareHeaders[i].value, metadata: metadata});
|
|
1566
|
+
}
|
|
1567
|
+
sheetData.push(headerData);
|
|
1568
|
+
|
|
1569
|
+
var result = exportData.map(this.formatRowAsExcel(this, workbook, sheet));
|
|
1570
|
+
for (var j = 0; j<result.length; j++) {
|
|
1571
|
+
sheetData.push(result[j]);
|
|
1572
|
+
}
|
|
1573
|
+
return sheetData;
|
|
1574
|
+
},
|
|
1575
|
+
|
|
1576
|
+
/**
|
|
1577
|
+
* @ngdoc function
|
|
1578
|
+
* @name formatRowAsExcel
|
|
1579
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1580
|
+
* @description Renders a single field as a csv field, including
|
|
1581
|
+
* quotes around the value
|
|
1582
|
+
* @param {exporterService} exporter pass in exporter
|
|
1583
|
+
* @param {array} row the row to be turned into a excel string
|
|
1584
|
+
* @returns {array} array of cell objects (i.e. {value: x, metadata: y})
|
|
1585
|
+
*/
|
|
1586
|
+
formatRowAsExcel: function (exporter, workbook, sheet) {
|
|
1587
|
+
return function (row) {
|
|
1588
|
+
var values = [];
|
|
1589
|
+
for (var i = 0; i<row.length; i++) {
|
|
1590
|
+
var value = exporter.formatFieldAsExcel(row[i], workbook, sheet);
|
|
1591
|
+
values.push({value: value, metadata: row[i].metadata});
|
|
1592
|
+
}
|
|
1593
|
+
return values;
|
|
1594
|
+
};
|
|
1595
|
+
},
|
|
1596
|
+
|
|
1597
|
+
/**
|
|
1598
|
+
* @ngdoc function
|
|
1599
|
+
* @name formatFieldAsExcel
|
|
1600
|
+
* @methodOf ui.grid.exporter.service:uiGridExporterService
|
|
1601
|
+
* @description Renders a single field as a excel-ified field
|
|
1602
|
+
* @param {field} field the field to be excel-ified,
|
|
1603
|
+
* may be of any type
|
|
1604
|
+
* @returns {string} a excel-ified version of the field
|
|
1605
|
+
*/
|
|
1606
|
+
formatFieldAsExcel: function (field, workbook, sheet, formatters) {
|
|
1607
|
+
if (field.value == null) { // we want to catch anything null-ish, hence just == not ===
|
|
1608
|
+
return '';
|
|
1609
|
+
}
|
|
1610
|
+
if ((typeof(field.value) === 'number') || (typeof(field.value) === 'string')) {
|
|
1611
|
+
return field.value;
|
|
1612
|
+
}
|
|
1613
|
+
if (typeof(field.value) === 'boolean') {
|
|
1614
|
+
return (field.value ? 'TRUE' : 'FALSE') ;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
return JSON.stringify(field.value);
|
|
1618
|
+
},
|
|
1619
|
+
|
|
1620
|
+
prepareAsExcel: function(grid, workbook, sheet) {
|
|
1621
|
+
var docDefinition = {
|
|
1622
|
+
styles: {
|
|
1623
|
+
|
|
1624
|
+
}
|
|
1625
|
+
};
|
|
1626
|
+
|
|
1627
|
+
if ( grid.options.exporterExcelCustomFormatters ) {
|
|
1628
|
+
docDefinition = grid.options.exporterExcelCustomFormatters( grid, workbook, docDefinition );
|
|
1629
|
+
}
|
|
1630
|
+
if ( grid.options.exporterExcelHeader ) {
|
|
1631
|
+
if (angular.isFunction( grid.options.exporterExcelHeader )) {
|
|
1632
|
+
grid.options.exporterExcelHeader(grid, workbook, sheet, docDefinition);
|
|
1633
|
+
} else {
|
|
1634
|
+
var headerText = grid.options.exporterExcelHeader.text;
|
|
1635
|
+
var style = grid.options.exporterExcelHeader.style;
|
|
1636
|
+
sheet.data.push([{value: headerText, metadata: {style: docDefinition.styles[style].id}}]);
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
return docDefinition;
|
|
1641
|
+
},
|
|
1642
|
+
|
|
1643
|
+
excelExport: function (grid, rowTypes, colTypes) {
|
|
1644
|
+
var self = this;
|
|
1645
|
+
self.type = 'excel';
|
|
1646
|
+
this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function() {
|
|
1647
|
+
var exportColumnHeaders = grid.options.showHeader ? self.getColumnHeaders(grid, colTypes) : [];
|
|
1648
|
+
|
|
1649
|
+
var aName = 'Sheet1';
|
|
1650
|
+
if (grid.options.exporterExcelSheetName) {
|
|
1651
|
+
aName = angular.isFunction(grid.options.exporterExcelSheetName) ? grid.options.exporterExcelSheetName(grid, rowTypes, colTypes) : grid.options.exporterExcelSheetName;
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
var sheet = new ExcelBuilder.Worksheet({name: aName});
|
|
1655
|
+
var workbook = new ExcelBuilder.Workbook();
|
|
1656
|
+
workbook.addWorksheet(sheet);
|
|
1657
|
+
var docDefinition = self.prepareAsExcel(grid, workbook, sheet);
|
|
1658
|
+
|
|
1659
|
+
// The standard column width in Microsoft Excel 2000 is 8.43 characters based on fixed-width Courier font
|
|
1660
|
+
// Width of 10 in excel is 75 pixels
|
|
1661
|
+
var colWidths = [];
|
|
1662
|
+
var startDataIndex = grid.treeBase ? grid.treeBase.numberLevels : (grid.enableRowSelection ? 1 : 0);
|
|
1663
|
+
for (var i = startDataIndex; i < grid.columns.length; i++) {
|
|
1664
|
+
if (grid.columns[i].field !== uiGridExporterConstants.rowHeaderColName &&
|
|
1665
|
+
grid.columns[i].field !== uiGridExporterConstants.selectionRowHeaderColName) {
|
|
1666
|
+
|
|
1667
|
+
colWidths.push({width: (grid.columns[i].drawnWidth / grid.options.exporterColumnScaleFactor)});
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
sheet.setColumns(colWidths);
|
|
1671
|
+
|
|
1672
|
+
var exportData = self.getData(grid, rowTypes, colTypes, grid.options.exporterFieldApplyFilters);
|
|
1673
|
+
|
|
1674
|
+
var excelContent = self.formatAsExcel(exportColumnHeaders, exportData, workbook, sheet, docDefinition);
|
|
1675
|
+
sheet.setData(sheet.data.concat(excelContent));
|
|
1676
|
+
|
|
1677
|
+
ExcelBuilder.Builder.createFile(workbook, {type: 'blob'}).then(function(result) {
|
|
1678
|
+
var fileName = angular.isFunction(grid.options.exporterExcelFilename) ? grid.options.exporterExcelFilename(grid, rowTypes, colTypes) : grid.options.exporterExcelFilename;
|
|
1679
|
+
self.downloadFile(fileName, result, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility);
|
|
1680
|
+
});
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
|
|
1685
|
+
function getDisplayName(grid, gridCol) {
|
|
1686
|
+
if (grid.options.exporterHeaderFilter) {
|
|
1687
|
+
return grid.options.exporterHeaderFilterUseName ?
|
|
1688
|
+
grid.options.exporterHeaderFilter(gridCol.name) :
|
|
1689
|
+
grid.options.exporterHeaderFilter(gridCol.displayName);
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
return gridCol.headerCellFilter ?
|
|
1693
|
+
$filter(gridCol.headerCellFilter)(gridCol.displayName) :
|
|
1694
|
+
gridCol.displayName;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
function defaultExporterFieldCallback(grid, row, col, value) {
|
|
1698
|
+
// fix to handle cases with 'number : 1' or 'date:"MM-dd-YYYY HH:mm"', etc.. We needed to split the string
|
|
1699
|
+
if (col.cellFilter) {
|
|
1700
|
+
var args, filter, arg1, arg2;
|
|
1701
|
+
// Split on ':' except when in double quotes.
|
|
1702
|
+
args = col.cellFilter.match(/(?:[^:"]+|"[^"]*")+/g);
|
|
1703
|
+
// remove space, single/double to maintain retro-compatibility, but keep spaces in second argument (arg[1])
|
|
1704
|
+
filter = args[0] ? args[0].replace(/[\'\"\s]/g, "") : null;
|
|
1705
|
+
arg1 = args[1] ? args[1].replace(/[\'\"]/g, "").trim() : null;
|
|
1706
|
+
arg2 = args[2] ? args[2].replace(/[\'\"\s]/g, "") : null;
|
|
1707
|
+
return $filter(filter)(value, arg1, arg2);
|
|
1708
|
+
} else {
|
|
1709
|
+
return value;
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
return service;
|
|
1714
|
+
}
|
|
1715
|
+
]);
|
|
1716
|
+
|
|
1717
|
+
/**
|
|
1718
|
+
* @ngdoc directive
|
|
1719
|
+
* @name ui.grid.exporter.directive:uiGridExporter
|
|
1720
|
+
* @element div
|
|
1721
|
+
* @restrict A
|
|
1722
|
+
*
|
|
1723
|
+
* @description Adds exporter features to grid
|
|
1724
|
+
*
|
|
1725
|
+
* @example
|
|
1726
|
+
<example module="app">
|
|
1727
|
+
<file name="app.js">
|
|
1728
|
+
var app = angular.module('app', ['ui.grid', 'ui.grid.exporter']);
|
|
1729
|
+
|
|
1730
|
+
app.controller('MainCtrl', ['$scope', function ($scope) {
|
|
1731
|
+
$scope.data = [
|
|
1732
|
+
{ name: 'Bob', title: 'CEO' },
|
|
1733
|
+
{ name: 'Frank', title: 'Lowly Developer' }
|
|
1734
|
+
];
|
|
1735
|
+
|
|
1736
|
+
$scope.gridOptions = {
|
|
1737
|
+
enableGridMenu: true,
|
|
1738
|
+
exporterMenuCsv: false,
|
|
1739
|
+
columnDefs: [
|
|
1740
|
+
{name: 'name', enableCellEdit: true},
|
|
1741
|
+
{name: 'title', enableCellEdit: true}
|
|
1742
|
+
],
|
|
1743
|
+
data: $scope.data
|
|
1744
|
+
};
|
|
1745
|
+
}]);
|
|
1746
|
+
</file>
|
|
1747
|
+
<file name="index.html">
|
|
1748
|
+
<div ng-controller="MainCtrl">
|
|
1749
|
+
<div ui-grid="gridOptions" ui-grid-exporter></div>
|
|
1750
|
+
</div>
|
|
1751
|
+
</file>
|
|
1752
|
+
</example>
|
|
1753
|
+
*/
|
|
1754
|
+
module.directive('uiGridExporter', ['uiGridExporterConstants', 'uiGridExporterService', 'gridUtil', '$compile',
|
|
1755
|
+
function (uiGridExporterConstants, uiGridExporterService, gridUtil, $compile) {
|
|
1756
|
+
return {
|
|
1757
|
+
replace: true,
|
|
1758
|
+
priority: 0,
|
|
1759
|
+
require: '^uiGrid',
|
|
1760
|
+
scope: false,
|
|
1761
|
+
link: function ($scope, $elm, $attrs, uiGridCtrl) {
|
|
1762
|
+
uiGridExporterService.initializeGrid(uiGridCtrl.grid);
|
|
1763
|
+
uiGridCtrl.grid.exporter.$scope = $scope;
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
]);
|
|
1768
|
+
})();
|
|
1769
|
+
|
|
1770
|
+
angular.module('ui.grid.exporter').run(['$templateCache', function($templateCache) {
|
|
1771
|
+
'use strict';
|
|
1772
|
+
|
|
1773
|
+
$templateCache.put('ui-grid/csvLink',
|
|
1774
|
+
"<span class=\"ui-grid-exporter-csv-link-span\"><a href=\"data:text/csv;charset=UTF-8,CSV_CONTENT\" download=\"FILE_NAME\">LINK_LABEL</a></span>"
|
|
1775
|
+
);
|
|
1776
|
+
|
|
1777
|
+
}]);
|