Skip to content

Commit bfbeeed

Browse files
monster910mportuga
authored andcommitted
docs(excel_exporting): Add date column and fix examples.
* Initial checkin of export to excel. No examples or unit tests * Eliminate $$hashKey and uidPrefix = 'uiGrid' from export * Sheet name cannot be empty string or it causes export errors. Default to 'Sheet1' * Additional languages * Add documentation * fix syntax causing lint errors. Check if not a tree when exporting to prevent error * Updated example with colors * Update unit tests and fix the lodash version for import to remove ambiguity. * Update comments * Fix menu under strict mode from throwing error * Updated directions for npm and add more formatting examples * Fix test cases for excel export that was a merge error * fix(exporter): Fix bug where selection column width was included * docs(410_excel_exporting*.ngdoc): Add date column and example with exporting with cellFilters * docs(410_excel_exporting*.ngdoc): Fix for native excel 2017. No 'type' * Resolving merge conflict
1 parent d6aeb16 commit bfbeeed

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

misc/tutorial/410_excel_exporting_data_and_header.ngdoc

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,35 @@ In this example we use the native grid menu buttons, and we show the pdf, csv an
5151

5252
$scope.formatters = {};
5353

54+
$scope.randomDate = function randomDate(start, end) {
55+
var diff = end.getTime() - start.getTime();
56+
var new_diff = diff * Math.random();
57+
var date = new Date(start.getTime() + new_diff);
58+
return date;
59+
};
60+
5461
$scope.gridOptions = {
5562
columnDefs: [
5663
{ field: 'name' },
5764
{ field: 'gender', visible: false},
5865
{ field: 'company' },
5966
{ field: 'member' },
60-
{ field: 'total' }
67+
{ field: 'total' },
68+
{ field: 'updatedDate', displayName: 'Date', cellFilter: 'date:\'yyyy-MM-dd\'', width: 150,
69+
sortingAlgorithm: function (aDate, bDate) {
70+
var a=new Date(aDate);
71+
var b=new Date(bDate);
72+
if (a < b) {
73+
return -1;
74+
}
75+
else if (a > b) {
76+
return 1;
77+
}
78+
else {
79+
return 0;
80+
}
81+
}
82+
}
6183
],
6284
enableGridMenu: true,
6385
enableSelectAll: true,
@@ -96,6 +118,8 @@ In this example we use the native grid menu buttons, and we show the pdf, csv an
96118
var formatter = stylesheet.createFormat(aFormatDefn);
97119
// save the formatter
98120
$scope.formatters['bold'] = formatter;
121+
var dateFormatter = stylesheet.createSimpleFormatter('date');
122+
$scope.formatters['date'] = dateFormatter;
99123

100124
aFormatDefn = {
101125
"font": stdStyle.id,
@@ -136,16 +160,21 @@ In this example we use the native grid menu buttons, and we show the pdf, csv an
136160
// set metadata on export data to set format id. See exportExcelHeader config above for example of creating
137161
// a formatter and obtaining the id
138162
var formatterId = null;
139-
if (cellValue && typeof cellValue === 'string' && cellValue.startsWith('W')) {
163+
if (gridCol.field === 'name' && cellValue && cellValue.startsWith('W')) {
140164
formatterId = $scope.formatters['red'].id;
141165
}
142166

167+
if (gridCol.field === 'updatedDate') {
168+
formatterId = $scope.formatters['date'].id;
169+
}
170+
143171
if (formatterId) {
144172
return {metadata: {style: formatterId}};
145173
} else {
146174
return null;
147175
}
148-
},
176+
},
177+
exporterFieldApplyFilters: true,
149178
onRegisterApi: function(gridApi){
150179
$scope.gridApi = gridApi;
151180
}
@@ -158,9 +187,11 @@ In this example we use the native grid menu buttons, and we show the pdf, csv an
158187
for (var i=0; i < data.length; i++) {
159188
data[i].member = false;
160189
data[i].total = i + 0.1;
190+
data[i].updatedDate = $scope.randomDate(new Date('09-11-2008'), new Date());
161191
}
162192
$scope.gridOptions.data = data;
163193
});
194+
164195
}]);
165196
</file>
166197

0 commit comments

Comments
 (0)