1
1
import { Component , OnInit , ViewChild } from '@angular/core' ;
2
- import { IgxGridComponent , ColumnPinningPosition , RowPinningPosition , IgxGridRowComponent , IgxTransactionService , IgxGridTransaction , IgxGridStateDirective } from 'igniteui-angular' ;
2
+ import {
3
+ IgxGridComponent ,
4
+ ColumnPinningPosition ,
5
+ RowPinningPosition , IgxGridRowComponent ,
6
+ IgxTransactionService ,
7
+ IgxGridTransaction ,
8
+ IgxGridStateDirective ,
9
+ IgxExcelExporterService ,
10
+ IgxExcelExporterOptions
11
+ } from 'igniteui-angular' ;
3
12
import { IPinningConfig } from 'projects/igniteui-angular/src/lib/grids/common/grid.interface' ;
4
13
5
14
@Component ( {
@@ -23,13 +32,16 @@ export class GridRowPinningSampleComponent implements OnInit {
23
32
columns : false ,
24
33
rowPinning : true ,
25
34
pinningConfig : true
26
- } ;
35
+ } ;
27
36
28
37
@ViewChild ( 'grid1' , { static : true } )
29
38
grid1 : IgxGridComponent ;
30
39
31
40
@ViewChild ( IgxGridStateDirective , { static : true } ) public state : IgxGridStateDirective ;
32
41
42
+ constructor ( private excelExportService : IgxExcelExporterService ) {
43
+ }
44
+
33
45
onRowChange ( ) {
34
46
if ( this . pinningConfig . rows === RowPinningPosition . Bottom ) {
35
47
this . pinningConfig = { columns : this . pinningConfig . columns , rows : RowPinningPosition . Top } ;
@@ -42,7 +54,7 @@ export class GridRowPinningSampleComponent implements OnInit {
42
54
if ( this . pinningConfig . columns === ColumnPinningPosition . End ) {
43
55
this . pinningConfig = { columns : ColumnPinningPosition . Start , rows : this . pinningConfig . rows } ;
44
56
} else {
45
- this . pinningConfig = { columns : ColumnPinningPosition . End , rows : this . pinningConfig . rows } ;
57
+ this . pinningConfig = { columns : ColumnPinningPosition . End , rows : this . pinningConfig . rows } ;
46
58
}
47
59
}
48
60
@@ -53,7 +65,7 @@ export class GridRowPinningSampleComponent implements OnInit {
53
65
this . columns = [
54
66
{ field : 'ID' , width : '200px' , hidden : true } ,
55
67
{ field : 'CompanyName' , width : '200px' , groupable : true } ,
56
- { field : 'ContactName' , width : '200px' , pinned : false , groupable : true } ,
68
+ { field : 'ContactName' , width : '200px' , pinned : false , groupable : true } ,
57
69
{ field : 'ContactTitle' , width : '300px' , pinned : false , groupable : true } ,
58
70
{ field : 'Address' , width : '250px' } ,
59
71
{ field : 'City' , width : '200px' } ,
@@ -98,28 +110,31 @@ export class GridRowPinningSampleComponent implements OnInit {
98
110
99
111
togglePinRow ( index ) {
100
112
const rec = this . data [ index ] ;
101
- this . grid1 . isRecordPinned ( rec ) ?
102
- this . grid1 . pinRow ( this . data [ index ] ) :
103
- this . grid1 . unpinRow ( this . data [ index ] )
113
+ this . grid1 . isRecordPinned ( rec ) ?
114
+ this . grid1 . pinRow ( this . data [ index ] ) :
115
+ this . grid1 . unpinRow ( this . data [ index ] )
104
116
}
105
117
106
118
togglePining ( row : IgxGridRowComponent , event ) {
107
119
event . preventDefault ( ) ;
108
- if ( row . pinned ) {
120
+ if ( row . pinned ) {
109
121
row . unpin ( ) ;
110
122
} else {
111
123
row . pin ( ) ;
112
124
}
113
125
}
114
126
127
+ public exportButtonHandler ( ) {
128
+ this . excelExportService . export ( this . grid1 , new IgxExcelExporterOptions ( "ExportFileFromGrid" ) ) ;
129
+ }
130
+
115
131
public saveGridState ( ) {
116
132
const state = this . state . getState ( ) as string ;
117
133
window . localStorage . setItem ( "grid1-state" , state ) ;
118
134
}
119
-
135
+
120
136
public restoreGridState ( ) {
121
137
const state = window . localStorage . getItem ( "grid1-state" ) ;
122
138
this . state . setState ( state ) ;
123
139
}
124
-
125
140
}
0 commit comments