@@ -2,6 +2,9 @@ import { Component, Injectable, OnInit, OnDestroy } from '@angular/core';
2
2
import { Column , Editors , FieldType , Formatters , GridExtraService , GridExtraUtils , GridOption , OnEventArgs , ResizerService } from './../modules/angular-slickgrid' ;
3
3
import { TranslateService } from '@ngx-translate/core' ;
4
4
5
+ // using external non-typed js libraries
6
+ declare var Slick : any ;
7
+
5
8
@Component ( {
6
9
templateUrl : './grid-editor.component.html'
7
10
} )
@@ -17,10 +20,12 @@ export class GridEditorComponent implements OnInit, OnDestroy {
17
20
</ul>
18
21
` ;
19
22
23
+ private _commandQueue = [ ] ;
20
24
columnDefinitions : Column [ ] ;
21
25
gridOptions : GridOption ;
22
26
dataset : any [ ] ;
23
27
isAutoEdit = true ;
28
+ alertWarning : any ;
24
29
updatedObject : any ;
25
30
gridObj : any ;
26
31
dataviewObj : any ;
@@ -31,6 +36,7 @@ export class GridEditorComponent implements OnInit, OnDestroy {
31
36
ngOnInit ( ) : void {
32
37
this . prepareGrid ( ) ;
33
38
}
39
+
34
40
ngOnDestroy ( ) : void {
35
41
// unsubscrible any Slick.Event you might have used
36
42
// a reminder again, these are SlickGrid Event, not RxJS events
@@ -48,7 +54,7 @@ export class GridEditorComponent implements OnInit, OnDestroy {
48
54
// use onCellClick OR grid.onClick.subscribe which you can see down below
49
55
onCellClick : ( args : OnEventArgs ) => {
50
56
console . log ( args ) ;
51
- alert ( `Editing: ${ args . dataContext . title } ` ) ;
57
+ this . alertWarning = `Editing: ${ args . dataContext . title } ` ;
52
58
this . gridExtraService . highlightRow ( args . row , 1500 ) ;
53
59
this . gridExtraService . setSelectedRow ( args . row ) ;
54
60
}
@@ -61,14 +67,14 @@ export class GridEditorComponent implements OnInit, OnDestroy {
61
67
// use onCellClick OR grid.onClick.subscribe which you can see down below
62
68
onCellClick : ( args : OnEventArgs ) => {
63
69
console . log ( args ) ;
64
- alert ( `Deleting: ${ args . dataContext . title } ` ) ;
70
+ this . alertWarning = `Deleting: ${ args . dataContext . title } ` ;
65
71
}
66
72
} ,
67
73
{ id : 'title' , name : 'Title' , field : 'title' , sortable : true , type : FieldType . string , editor : Editors . longText } ,
68
74
{ id : 'duration' , name : 'Duration (days)' , field : 'duration' , sortable : true , type : FieldType . number , editor : Editors . text ,
69
75
onCellChange : ( args : OnEventArgs ) => {
70
- alert ( 'onCellChange directly attached to the column definition' ) ;
71
- console . log ( args ) ;
76
+ console . log ( args ) ;
77
+ this . alertWarning = 'onCellChange triggered and attached to the column definition' ;
72
78
}
73
79
} ,
74
80
{ id : 'complete' , name : '% Complete' , field : 'percentComplete' , formatter : Formatters . percentCompleteBar , type : FieldType . number , editor : Editors . integer } ,
@@ -86,7 +92,11 @@ export class GridEditorComponent implements OnInit, OnDestroy {
86
92
} ,
87
93
editable : true ,
88
94
enableColumnPicker : true ,
89
- enableCellNavigation : true
95
+ enableCellNavigation : true ,
96
+ editCommandHandler : ( item , column , editCommand ) => {
97
+ this . _commandQueue . push ( editCommand ) ;
98
+ editCommand . execute ( ) ;
99
+ }
90
100
} ;
91
101
92
102
// mock a dataset
@@ -126,7 +136,7 @@ export class GridEditorComponent implements OnInit, OnDestroy {
126
136
const column = GridExtraUtils . getColumnDefinitionAndData ( args ) ;
127
137
console . log ( 'onClick' , args , column ) ;
128
138
if ( column . columnDef . id === 'edit' ) {
129
- alert ( ' open a modal window to edit: ' + column . dataContext . title ) ;
139
+ this . alertWarning = ` open a modal window to edit: ${ column . dataContext . title } ` ;
130
140
131
141
// highlight the row, to customize the color, you can change the SASS variable $row-highlight-background-color
132
142
this . gridExtraService . highlightRow ( args . row , 1500 ) ;
@@ -155,4 +165,12 @@ export class GridEditorComponent implements OnInit, OnDestroy {
155
165
this . selectedLanguage = ( this . selectedLanguage === 'en' ) ? 'fr' : 'en' ;
156
166
this . translate . use ( this . selectedLanguage ) ;
157
167
}
168
+
169
+ undo ( ) {
170
+ const command = this . _commandQueue . pop ( ) ;
171
+ if ( command && Slick . GlobalEditorLock . cancelCurrentEdit ( ) ) {
172
+ command . undo ( ) ;
173
+ this . gridObj . gotoCell ( command . row , command . cell , false ) ;
174
+ }
175
+ }
158
176
}
0 commit comments