1
1
import { Component , OnInit , ViewEncapsulation } from '@angular/core' ;
2
+ import { ExcelExportService } from '@slickgrid-universal/excel-export' ;
2
3
import { AngularGridInstance , Column , Formatter , GridOption , type ItemMetadata } from './../modules/angular-slickgrid' ;
3
4
4
- const rowCellValueFormatter : Formatter = ( row , cell , value ) => {
5
- return `<div class="cellValue">${ value . toFixed ( 2 ) } </div><div class="valueComment">${ row } .${ cell } </div>` ;
6
- } ;
5
+ const rowCellValueFormatter : Formatter = ( row , cell , value ) =>
6
+ `<div class="cellValue">${ value . toFixed ( 2 ) } </div><div class="valueComment">${ row } .${ cell } </div>` ;
7
+ const rowCellValueExportFormatter : Formatter = ( _row , _cell , value ) => value . toFixed ( 2 ) ;
7
8
8
9
@Component ( {
9
10
styleUrls : [ 'grid44.component.scss' ] ,
@@ -75,60 +76,198 @@ export class Grid44Component implements OnInit {
75
76
defineGrid ( ) {
76
77
this . columnDefinitions = [
77
78
{ id : 'title' , name : 'Title' , field : 'title' , minWidth : 80 } ,
78
- { id : 'revenueGrowth' , name : 'Revenue Growth' , field : 'revenueGrowth' , formatter : rowCellValueFormatter , minWidth : 120 } ,
79
+ {
80
+ id : 'revenueGrowth' ,
81
+ name : 'Revenue Growth' ,
82
+ field : 'revenueGrowth' ,
83
+ exportCustomFormatter : rowCellValueExportFormatter ,
84
+ formatter : rowCellValueFormatter ,
85
+ type : 'number' ,
86
+ minWidth : 120 ,
87
+ } ,
79
88
{
80
89
id : 'pricingPolicy' ,
81
90
name : 'Pricing Policy' ,
82
91
field : 'pricingPolicy' ,
83
92
minWidth : 110 ,
84
93
sortable : true ,
94
+ exportCustomFormatter : rowCellValueExportFormatter ,
95
+ formatter : rowCellValueFormatter ,
96
+ type : 'number' ,
97
+ } ,
98
+ {
99
+ id : 'policyIndex' ,
100
+ name : 'Policy Index' ,
101
+ field : 'policyIndex' ,
102
+ minWidth : 100 ,
103
+ exportCustomFormatter : rowCellValueExportFormatter ,
104
+ formatter : rowCellValueFormatter ,
105
+ type : 'number' ,
106
+ } ,
107
+ {
108
+ id : 'expenseControl' ,
109
+ name : 'Expense Control' ,
110
+ field : 'expenseControl' ,
111
+ minWidth : 110 ,
112
+ exportCustomFormatter : rowCellValueExportFormatter ,
113
+ formatter : rowCellValueFormatter ,
114
+ type : 'number' ,
115
+ } ,
116
+ {
117
+ id : 'excessCash' ,
118
+ name : 'Excess Cash' ,
119
+ field : 'excessCash' ,
120
+ minWidth : 100 ,
121
+ exportCustomFormatter : rowCellValueExportFormatter ,
85
122
formatter : rowCellValueFormatter ,
123
+ type : 'number' ,
124
+ } ,
125
+ {
126
+ id : 'netTradeCycle' ,
127
+ name : 'Net Trade Cycle' ,
128
+ field : 'netTradeCycle' ,
129
+ minWidth : 110 ,
130
+ exportCustomFormatter : rowCellValueExportFormatter ,
131
+ formatter : rowCellValueFormatter ,
132
+ type : 'number' ,
133
+ } ,
134
+ {
135
+ id : 'costCapital' ,
136
+ name : 'Cost of Capital' ,
137
+ field : 'costCapital' ,
138
+ minWidth : 100 ,
139
+ exportCustomFormatter : rowCellValueExportFormatter ,
140
+ formatter : rowCellValueFormatter ,
141
+ type : 'number' ,
142
+ } ,
143
+ {
144
+ id : 'revenueGrowth2' ,
145
+ name : 'Revenue Growth' ,
146
+ field : 'revenueGrowth2' ,
147
+ exportCustomFormatter : rowCellValueExportFormatter ,
148
+ formatter : rowCellValueFormatter ,
149
+ type : 'number' ,
150
+ minWidth : 120 ,
86
151
} ,
87
- { id : 'policyIndex' , name : 'Policy Index' , field : 'policyIndex' , minWidth : 100 , formatter : rowCellValueFormatter } ,
88
- { id : 'expenseControl' , name : 'Expense Control' , field : 'expenseControl' , minWidth : 110 , formatter : rowCellValueFormatter } ,
89
- { id : 'excessCash' , name : 'Excess Cash' , field : 'excessCash' , minWidth : 100 , formatter : rowCellValueFormatter } ,
90
- { id : 'netTradeCycle' , name : 'Net Trade Cycle' , field : 'netTradeCycle' , minWidth : 110 , formatter : rowCellValueFormatter } ,
91
- { id : 'costCapital' , name : 'Cost of Capital' , field : 'costCapital' , minWidth : 100 , formatter : rowCellValueFormatter } ,
92
- { id : 'revenueGrowth2' , name : 'Revenue Growth' , field : 'revenueGrowth2' , formatter : rowCellValueFormatter , minWidth : 120 } ,
93
152
{
94
153
id : 'pricingPolicy2' ,
95
154
name : 'Pricing Policy' ,
96
155
field : 'pricingPolicy2' ,
97
156
minWidth : 110 ,
98
157
sortable : true ,
158
+ exportCustomFormatter : rowCellValueExportFormatter ,
159
+ formatter : rowCellValueFormatter ,
160
+ type : 'number' ,
161
+ } ,
162
+ {
163
+ id : 'policyIndex2' ,
164
+ name : 'Policy Index' ,
165
+ field : 'policyIndex2' ,
166
+ minWidth : 100 ,
167
+ exportCustomFormatter : rowCellValueExportFormatter ,
99
168
formatter : rowCellValueFormatter ,
169
+ type : 'number' ,
100
170
} ,
101
- { id : 'policyIndex2' , name : 'Policy Index' , field : 'policyIndex2' , minWidth : 100 , formatter : rowCellValueFormatter } ,
102
171
{
103
172
id : 'expenseControl2' ,
104
173
name : 'Expense Control' ,
105
174
field : 'expenseControl2' ,
106
175
minWidth : 110 ,
176
+ exportCustomFormatter : rowCellValueExportFormatter ,
107
177
formatter : rowCellValueFormatter ,
178
+ type : 'number' ,
179
+ } ,
180
+ {
181
+ id : 'excessCash2' ,
182
+ name : 'Excess Cash' ,
183
+ field : 'excessCash2' ,
184
+ minWidth : 100 ,
185
+ exportCustomFormatter : rowCellValueExportFormatter ,
186
+ formatter : rowCellValueFormatter ,
187
+ type : 'number' ,
188
+ } ,
189
+ {
190
+ id : 'netTradeCycle2' ,
191
+ name : 'Net Trade Cycle' ,
192
+ field : 'netTradeCycle2' ,
193
+ minWidth : 110 ,
194
+ exportCustomFormatter : rowCellValueExportFormatter ,
195
+ formatter : rowCellValueFormatter ,
196
+ type : 'number' ,
197
+ } ,
198
+ {
199
+ id : 'costCapital2' ,
200
+ name : 'Cost of Capital' ,
201
+ field : 'costCapital2' ,
202
+ minWidth : 100 ,
203
+ exportCustomFormatter : rowCellValueExportFormatter ,
204
+ formatter : rowCellValueFormatter ,
205
+ type : 'number' ,
206
+ } ,
207
+ {
208
+ id : 'revenueGrowth3' ,
209
+ name : 'Revenue Growth' ,
210
+ field : 'revenueGrowth3' ,
211
+ exportCustomFormatter : rowCellValueExportFormatter ,
212
+ formatter : rowCellValueFormatter ,
213
+ type : 'number' ,
214
+ minWidth : 120 ,
108
215
} ,
109
- { id : 'excessCash2' , name : 'Excess Cash' , field : 'excessCash2' , minWidth : 100 , formatter : rowCellValueFormatter } ,
110
- { id : 'netTradeCycle2' , name : 'Net Trade Cycle' , field : 'netTradeCycle2' , minWidth : 110 , formatter : rowCellValueFormatter } ,
111
- { id : 'costCapital2' , name : 'Cost of Capital' , field : 'costCapital2' , minWidth : 100 , formatter : rowCellValueFormatter } ,
112
- { id : 'revenueGrowth3' , name : 'Revenue Growth' , field : 'revenueGrowth3' , formatter : rowCellValueFormatter , minWidth : 120 } ,
113
216
{
114
217
id : 'pricingPolicy3' ,
115
218
name : 'Pricing Policy' ,
116
219
field : 'pricingPolicy3' ,
117
220
minWidth : 110 ,
118
221
sortable : true ,
222
+ exportCustomFormatter : rowCellValueExportFormatter ,
119
223
formatter : rowCellValueFormatter ,
224
+ type : 'number' ,
225
+ } ,
226
+ {
227
+ id : 'policyIndex3' ,
228
+ name : 'Policy Index' ,
229
+ field : 'policyIndex3' ,
230
+ minWidth : 100 ,
231
+ exportCustomFormatter : rowCellValueExportFormatter ,
232
+ formatter : rowCellValueFormatter ,
233
+ type : 'number' ,
120
234
} ,
121
- { id : 'policyIndex3' , name : 'Policy Index' , field : 'policyIndex3' , minWidth : 100 , formatter : rowCellValueFormatter } ,
122
235
{
123
236
id : 'expenseControl3' ,
124
237
name : 'Expense Control' ,
125
238
field : 'expenseControl3' ,
126
239
minWidth : 110 ,
240
+ exportCustomFormatter : rowCellValueExportFormatter ,
241
+ formatter : rowCellValueFormatter ,
242
+ type : 'number' ,
243
+ } ,
244
+ {
245
+ id : 'excessCash3' ,
246
+ name : 'Excess Cash' ,
247
+ field : 'excessCash3' ,
248
+ minWidth : 100 ,
249
+ exportCustomFormatter : rowCellValueExportFormatter ,
250
+ formatter : rowCellValueFormatter ,
251
+ type : 'number' ,
252
+ } ,
253
+ {
254
+ id : 'netTradeCycle3' ,
255
+ name : 'Net Trade Cycle' ,
256
+ field : 'netTradeCycle3' ,
257
+ minWidth : 110 ,
258
+ exportCustomFormatter : rowCellValueExportFormatter ,
259
+ formatter : rowCellValueFormatter ,
260
+ type : 'number' ,
261
+ } ,
262
+ {
263
+ id : 'costCapital3' ,
264
+ name : 'Cost of Capital' ,
265
+ field : 'costCapital3' ,
266
+ minWidth : 100 ,
267
+ exportCustomFormatter : rowCellValueExportFormatter ,
127
268
formatter : rowCellValueFormatter ,
269
+ type : 'number' ,
128
270
} ,
129
- { id : 'excessCash3' , name : 'Excess Cash' , field : 'excessCash3' , minWidth : 100 , formatter : rowCellValueFormatter } ,
130
- { id : 'netTradeCycle3' , name : 'Net Trade Cycle' , field : 'netTradeCycle3' , minWidth : 110 , formatter : rowCellValueFormatter } ,
131
- { id : 'costCapital3' , name : 'Cost of Capital' , field : 'costCapital3' , minWidth : 100 , formatter : rowCellValueFormatter } ,
132
271
] ;
133
272
134
273
this . gridOptions = {
@@ -143,6 +282,8 @@ export class Grid44Component implements OnInit {
143
282
getRowMetadata : ( item : any , row : number ) => this . renderDifferentColspan ( item , row ) ,
144
283
} ,
145
284
} ,
285
+ enableExcelExport : true ,
286
+ externalResources : [ new ExcelExportService ( ) ] ,
146
287
rowTopOffsetRenderType : 'top' , // rowspan doesn't render well with 'transform', default is 'top'
147
288
} ;
148
289
}
0 commit comments