11import { Component , OnInit , ViewEncapsulation } from '@angular/core' ;
2+ import { ExcelExportService } from '@slickgrid-universal/excel-export' ;
23import { AngularGridInstance , Column , Formatter , GridOption , type ItemMetadata } from './../modules/angular-slickgrid' ;
34
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 ) ;
78
89@Component ( {
910 styleUrls : [ 'grid44.component.scss' ] ,
@@ -75,60 +76,198 @@ export class Grid44Component implements OnInit {
7576 defineGrid ( ) {
7677 this . columnDefinitions = [
7778 { 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+ } ,
7988 {
8089 id : 'pricingPolicy' ,
8190 name : 'Pricing Policy' ,
8291 field : 'pricingPolicy' ,
8392 minWidth : 110 ,
8493 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 ,
85122 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 ,
86151 } ,
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 } ,
93152 {
94153 id : 'pricingPolicy2' ,
95154 name : 'Pricing Policy' ,
96155 field : 'pricingPolicy2' ,
97156 minWidth : 110 ,
98157 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 ,
99168 formatter : rowCellValueFormatter ,
169+ type : 'number' ,
100170 } ,
101- { id : 'policyIndex2' , name : 'Policy Index' , field : 'policyIndex2' , minWidth : 100 , formatter : rowCellValueFormatter } ,
102171 {
103172 id : 'expenseControl2' ,
104173 name : 'Expense Control' ,
105174 field : 'expenseControl2' ,
106175 minWidth : 110 ,
176+ exportCustomFormatter : rowCellValueExportFormatter ,
107177 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 ,
108215 } ,
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 } ,
113216 {
114217 id : 'pricingPolicy3' ,
115218 name : 'Pricing Policy' ,
116219 field : 'pricingPolicy3' ,
117220 minWidth : 110 ,
118221 sortable : true ,
222+ exportCustomFormatter : rowCellValueExportFormatter ,
119223 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' ,
120234 } ,
121- { id : 'policyIndex3' , name : 'Policy Index' , field : 'policyIndex3' , minWidth : 100 , formatter : rowCellValueFormatter } ,
122235 {
123236 id : 'expenseControl3' ,
124237 name : 'Expense Control' ,
125238 field : 'expenseControl3' ,
126239 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 ,
127268 formatter : rowCellValueFormatter ,
269+ type : 'number' ,
128270 } ,
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 } ,
132271 ] ;
133272
134273 this . gridOptions = {
@@ -143,6 +282,8 @@ export class Grid44Component implements OnInit {
143282 getRowMetadata : ( item : any , row : number ) => this . renderDifferentColspan ( item , row ) ,
144283 } ,
145284 } ,
285+ enableExcelExport : true ,
286+ externalResources : [ new ExcelExportService ( ) ] ,
146287 rowTopOffsetRenderType : 'top' , // rowspan doesn't render well with 'transform', default is 'top'
147288 } ;
148289 }
0 commit comments