-
-
Notifications
You must be signed in to change notification settings - Fork 120
/
grid-editor.component.ts
687 lines (639 loc) · 26.3 KB
/
grid-editor.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import fetchJsonp from 'fetch-jsonp';
import {
AngularGridInstance,
AutocompleterOption,
Column,
Editors,
EditorArguments,
EditorValidator,
FieldType,
Filters,
Formatter,
Formatters,
GridOption,
LongTextEditorOption,
type MultipleSelectOption,
OnEventArgs,
OperatorType,
SortComparers,
SlickGlobalEditorLock,
type VanillaCalendarOption,
} from './../modules/angular-slickgrid';
import { CustomInputEditor } from './custom-inputEditor';
import { CustomInputFilter } from './custom-inputFilter';
import { Subject } from 'rxjs';
const NB_ITEMS = 100;
const URL_SAMPLE_COLLECTION_DATA = 'assets/data/collection_100_numbers.json';
const URL_COUNTRIES_COLLECTION = 'assets/data/countries.json';
const URL_COUNTRY_NAMES = 'assets/data/country_names.json';
// you can create custom validator to pass to an inline editor
const myCustomTitleValidator: EditorValidator = (value: any, _args?: EditorArguments) => {
// you can get the Editor Args which can be helpful, e.g. we can get the Translate Service from it
/*
const grid = args && args.grid;
const gridOptions = (grid?.getOptions() ?? {}) as GridOption;
const translate = gridOptions.i18n;
const columnEditor = args?.column?.editor;
*/
if (value === null || value === undefined || !value.length) {
return { valid: false, msg: 'This is a required field' };
} else if (!/^Task\s\d+$/.test(value)) {
return { valid: false, msg: 'Your title is invalid, it must start with "Task" followed by a number' };
// OR use the Translate Service with your custom message
// return { valid: false, msg: translate.instant('YOUR_ERROR', { x: value }) };
}
return { valid: true, msg: '' };
};
// create a custom Formatter to show the Task + value
const taskFormatter: Formatter = (_row, _cell, value) => {
if (value && Array.isArray(value)) {
const taskValues = value.map((val) => `Task ${val}`);
const values = taskValues.join(', ');
return `<span title="${values}">${values}</span>`;
}
return '';
};
@Component({
templateUrl: './grid-editor.component.html'
})
export class GridEditorComponent implements OnInit {
title = 'Example 3: Editors / Delete';
subTitle = `
Grid with Inline Editors and onCellClick actions (<a href="https://ghiscoding.gitbook.io/angular-slickgrid/column-functionalities/editors" target="_blank">Wiki docs</a>).
<ul>
<li>Multiple Editors & Filters are available: AutoComplete, Checkbox, Date, Slider, SingleSelect, MultipleSelect, Float, Text, LongText... even Custom Editor</li>
<li>When using "enableCellNavigation: true", clicking on a cell will automatically make it active & selected.</li>
<ul><li>If you don't want this behavior, then you should disable "enableCellNavigation"</li></ul>
<li>Inline Editors requires "enableCellNavigation: true" (not sure why though)</li>
<li>
Support Excel Copy Buffer (SlickGrid Copy Manager Plugin), you can use it by simply enabling "enableExcelCopyBuffer" flag.
Note that it will only evaluate Formatter when the "exportWithFormatter" flag is enabled (through "ExportOptions" or the column definition)
</li>
<li>MultipleSelect & SingeSelect Editors & Filters can use a regular "collection" or "collectionAsync" to load it asynchronously</li>
<ul>
<li>Click on "Add Item" and see the Editor/Filter or the "Prerequesites" column change</li>
<li>Any Editor/Filter with a "collection" can be changed dynamically later in the future</li>
</ul>
</ul>
`;
private _commandQueue: any = [];
angularGrid!: AngularGridInstance;
columnDefinitions!: Column[];
gridOptions!: GridOption;
dataset!: any[];
gridObj: any;
isAutoEdit = true;
alertWarning: any;
updatedObject: any;
selectedLanguage = 'en';
duplicateTitleHeaderCount = 1;
constructor(private http: HttpClient, private translate: TranslateService) { }
ngOnInit() {
this.prepareGrid();
}
angularGridReady(angularGrid: AngularGridInstance) {
this.angularGrid = angularGrid;
this.gridObj = angularGrid.slickGrid;
}
prepareGrid() {
this.columnDefinitions = [
{
id: 'edit',
field: 'id',
excludeFromColumnPicker: true,
excludeFromGridMenu: true,
excludeFromHeaderMenu: true,
formatter: Formatters.icon,
params: { iconCssClass: 'mdi mdi-pencil pointer' },
minWidth: 30,
maxWidth: 30,
// use onCellClick OR grid.onClick.subscribe which you can see down below
onCellClick: (e: Event, args: OnEventArgs) => {
console.log(args);
this.alertWarning = `Editing: ${args.dataContext.title}`;
this.angularGrid.gridService.highlightRow(args.row, 1500);
this.angularGrid.gridService.setSelectedRow(args.row);
}
}, {
id: 'delete',
field: 'id',
excludeFromColumnPicker: true,
excludeFromGridMenu: true,
excludeFromHeaderMenu: true,
formatter: Formatters.icon,
params: { iconCssClass: 'mdi mdi-trash-can pointer' },
minWidth: 30,
maxWidth: 30,
// use onCellClick OR grid.onClick.subscribe which you can see down below
/*
onCellClick: (e: Event, args: OnEventArgs) => {
console.log(args);
this.alertWarning = `Deleting: ${args.dataContext.title}`;
}
*/
}, {
id: 'title',
name: 'Title',
field: 'title',
minWidth: 100,
filterable: true,
sortable: true,
type: FieldType.string,
editor: {
model: Editors.longText,
required: true,
maxLength: 12,
editorOptions: {
// you can change textarea cols,rows (defaults to 40,4)
cols: 42,
rows: 5,
buttonTexts: {
/* you can change button texts (defaults to "Cancel", "Save") */
// cancel: 'Close',
// save: 'Done'
/* or with translations (defaults to "CANCEL", "SAVE") */
// cancelKey: 'CANCEL',
// saveKey: 'SAVE'
}
} as LongTextEditorOption,
validator: myCustomTitleValidator,
},
onCellChange: (e: Event, args: OnEventArgs) => {
console.log(args);
this.alertWarning = `Updated Title: ${args.dataContext.title}`;
}
}, {
id: 'title2',
name: 'Title, Custom Editor',
field: 'title',
minWidth: 70,
filterable: true,
sortable: true,
type: FieldType.string,
editor: {
model: CustomInputEditor,
// model: Editors.text,
placeholder: 'custom',
validator: myCustomTitleValidator, // use a custom validator
},
filter: {
model: CustomInputFilter,
placeholder: '🔎︎ custom',
},
}, {
id: 'duration',
name: 'Duration (days)',
field: 'duration',
minWidth: 100,
filterable: true,
sortable: true,
formatter: Formatters.complexObject,
type: FieldType.number,
exportWithFormatter: true,
filter: { model: Filters.slider, filterOptions: { hideSliderNumber: false } },
editor: {
model: Editors.slider,
minValue: 0,
maxValue: 100,
// editorOptions: { hideSliderNumber: true },
},
/*
editor: {
// default is 0 decimals, if no decimals is passed it will accept 0 or more decimals
// however if you pass the "decimalPlaces", it will validate with that maximum
alwaysSaveOnEnterKey: true, // defaults to False, when set to true and user presses ENTER it will always call a Save even if value is empty
model: Editors.float,
placeholder: 'enter number',
title: 'Your number must be bigger than 5',
minValue: 5,
maxValue: 365,
// the default validation error message is in English but you can override it by using "errorMessage"
// errorMessage: this.i18n.tr('INVALID_FLOAT', { maxDecimal: 2 }),
params: { decimalPlaces: 2 },
},
*/
}, {
id: 'complete',
name: '% Complete',
field: 'percentComplete',
minWidth: 100,
filterable: true,
formatter: Formatters.multiple,
type: FieldType.number,
editor: {
model: Editors.singleSelect,
// We can also add HTML text to be rendered (any bad script will be sanitized) but we have to opt-in, else it will be sanitized
enableRenderHtml: true,
collection: Array.from(Array(101).keys()).map(k => ({ value: k, label: k, symbol: '<i class="mdi mdi-percent-outline" style="color:cadetblue"></i>' })),
customStructure: {
value: 'value',
label: 'label',
labelSuffix: 'symbol'
},
// collection: Array.from(Array(101).keys()).map(k => ({ value: k, label: k, labelSuffix: '%' })),
collectionSortBy: {
property: 'label',
sortDesc: true
},
collectionFilterBy: {
property: 'value',
value: 0,
operator: OperatorType.notEqual
},
// you could also provide a collection override to filter/sort based on the item dataContext or whatever else
// collectionOverride: (updatedCollection, args) => {
// console.log(args);
// return updatedCollection.filter((col) => args.dataContext.id % 2 ? col.value < 50 : col.value >= 50);
// },
editorOptions: {
maxHeight: 400
} as MultipleSelectOption
},
params: {
formatters: [Formatters.collectionEditor, Formatters.percentCompleteBar],
},
// validator: (value, args) => {
// if (value < 50) {
// return { valid: false, msg: 'Please use at least 50%' };
// }
// return { valid: true, msg: '' };
// }
}, {
id: 'start',
name: 'Start',
field: 'start',
minWidth: 100,
filterable: true,
filter: { model: Filters.compoundDate },
formatter: Formatters.multiple,
params: {
formatters: [Formatters.complexObject, Formatters.dateIso]
},
exportWithFormatter: true,
sortable: true,
type: FieldType.date,
editor: {
model: Editors.date,
},
}, {
id: 'finish',
name: 'Finish',
field: 'finish',
minWidth: 100,
filterable: true,
sortable: true,
filter: { model: Filters.compoundDate },
formatter: Formatters.dateIso,
exportWithFormatter: true,
type: FieldType.date, // dataset cell input format
// outputType: FieldType.dateUs, // date picker format
saveOutputType: FieldType.dateUtc, // save output date formattype: FieldType.date,
editor: {
model: Editors.date,
// override any of the calendar picker options through "editorOptions"
// please note that there's no TSlint on this property since it's generic for any filter, so make sure you entered the correct filter option(s)
editorOptions: {
range: { min: 'today' },
// if we want to preload the date picker with a different date,
// we could do it by assigning settings.seleted.dates
// NOTE: vanilla-calendar doesn't automatically focus the picker to the year/month and you need to do it yourself
// selected: {
// dates: ['2021-06-04'],
// month: 6 - 1, // Note: JS Date month (only) is zero index based, so June is 6-1 => 5
// year: 2021
// }
} as VanillaCalendarOption
},
}, {
id: 'cityOfOrigin', name: 'City of Origin', field: 'cityOfOrigin',
filterable: true,
minWidth: 100,
editor: {
model: Editors.autocompleter,
placeholder: '🔎︎ search city',
// We can use the autocomplete through 3 ways "collection", "collectionAsync" or with your own autocomplete options
// use your own autocomplete options, instead of fetch-jsonp, use http
// here we use fetch-jsonp just because I'm not sure how to configure http with JSONP and CORS
editorOptions: {
forceUserInput: true,
minLength: 3,
fetch: (searchText: string, updateCallback: (items: false | any[]) => void) => {
/** with Angular Http, note this demo won't work because of CORS */
// this.http.get(`http://gd.geobytes.com/AutoCompleteCity?q=${searchText}`).subscribe(data => updateCallback(data));
/** with JSONP AJAX will work locally but not on the GitHub demo because of CORS */
fetchJsonp(`http://gd.geobytes.com/AutoCompleteCity?q=${searchText}`)
.then((response) => response.json())
.then((json) => updateCallback(json))
.catch((ex) => console.log('invalid JSONP response', ex));
},
} as AutocompleterOption,
},
filter: {
model: Filters.autocompleter,
// placeholder: '🔎︎ search city',
// We can use the autocomplete through 3 ways "collection", "collectionAsync" or with your own autocomplete options
// collectionAsync: this.http.get(URL_COUNTRIES_COLLECTION),
// OR use the autocomplete through 3 ways "collection", "collectionAsync" or with your own autocomplete options
// use your own autocomplete options, instead of fetch-jsonp, use HttpClient or FetchClient
filterOptions: {
minLength: 3,
fetch: (searchText: string, updateCallback: (items: false | any[]) => void) => {
fetchJsonp(`http://gd.geobytes.com/AutoCompleteCity?q=${searchText}`)
.then((response) => response.json())
.then((json) => updateCallback(json))
.catch((ex) => console.log('invalid JSONP response', ex));
},
} as AutocompleterOption,
}
}, {
id: 'countryOfOrigin', name: 'Country of Origin', field: 'countryOfOrigin',
formatter: Formatters.complexObject,
exportWithFormatter: true,
dataKey: 'code',
labelKey: 'name',
type: FieldType.object,
sortComparer: SortComparers.objectString, // this sorter requires the dataKey and assume that obj1[dataKey] will be a string so it can sort it that way
filterable: true,
sortable: true,
minWidth: 100,
editor: {
model: Editors.autocompleter,
customStructure: { label: 'name', value: 'code' },
collectionAsync: this.http.get(URL_COUNTRIES_COLLECTION),
},
filter: {
model: Filters.autocompleter,
customStructure: { label: 'name', value: 'code' },
collectionAsync: this.http.get(URL_COUNTRIES_COLLECTION),
}
}, {
id: 'countryOfOriginName', name: 'Country of Origin Name', field: 'countryOfOriginName',
filterable: true,
sortable: true,
minWidth: 100,
editor: {
model: Editors.autocompleter,
collectionAsync: this.http.get(URL_COUNTRY_NAMES),
},
filter: {
model: Filters.autocompleter,
collectionAsync: this.http.get(URL_COUNTRY_NAMES),
}
}, {
id: 'effort-driven',
name: 'Effort Driven',
field: 'effortDriven',
minWidth: 70,
filterable: true,
type: FieldType.boolean,
filter: {
model: Filters.singleSelect,
collection: [{ value: '', label: '' }, { value: true, label: 'True' }, { value: false, label: 'False' }],
},
formatter: Formatters.checkmarkMaterial,
editor: {
model: Editors.checkbox,
},
}, {
id: 'prerequisites',
name: 'Prerequisites',
field: 'prerequisites',
minWidth: 100,
filterable: true,
formatter: taskFormatter,
exportWithFormatter: true,
sanitizeDataExport: true,
sortable: true,
type: FieldType.string,
editor: {
placeholder: 'choose option',
collectionAsync: this.http.get<{ value: string; label: string; }[]>(URL_SAMPLE_COLLECTION_DATA),
// OR a regular collection load
// collection: Array.from(Array(100).keys()).map(k => ({ value: k, prefix: 'Task', label: k })),
collectionSortBy: {
property: 'label',
sortDesc: true
},
customStructure: {
label: 'label',
value: 'value',
labelPrefix: 'prefix',
},
collectionOptions: {
separatorBetweenTextLabels: ' '
},
model: Editors.multipleSelect,
required: true
},
filter: {
collectionAsync: this.http.get<{ value: string; label: string; }[]>(URL_SAMPLE_COLLECTION_DATA),
// OR a regular collection load
// collection: Array.from(Array(100).keys()).map(k => ({ value: k, prefix: 'Task', label: k })),
collectionSortBy: {
property: 'label',
sortDesc: true
},
customStructure: {
label: 'label',
value: 'value',
labelPrefix: 'prefix',
},
collectionOptions: {
separatorBetweenTextLabels: ' '
},
model: Filters.multipleSelect,
operator: OperatorType.inContains,
}
}
];
this.gridOptions = {
asyncEditorLoading: false,
autoEdit: this.isAutoEdit,
autoCommitEdit: false,
autoResize: {
container: '#demo-container',
rightPadding: 10
},
editable: true,
enableCellNavigation: true,
enableColumnPicker: true,
enableExcelCopyBuffer: true,
enableFiltering: true,
editCommandHandler: (item, column, editCommand) => {
this._commandQueue.push(editCommand);
editCommand.execute();
},
i18n: this.translate
};
this.dataset = this.mockData(NB_ITEMS);
}
/** Add a new row to the grid and refresh the Filter collection.
* Note that because Filter elements are always displayed on the screen, we need to tell the Filter,
* we do this via a Subject .next(), that it's collection got changed
* as for the Editor, there's nothing to do since the element is not shown and it will have latest collection next time it shows up
*/
addItem() {
const lastRowIndex = this.dataset.length;
const newRows = this.mockData(1, lastRowIndex);
// wrap into a timer to simulate a backend async call
window.setTimeout(() => {
const requisiteColumnDef = this.columnDefinitions.find((column: Column) => column.id === 'prerequisites');
if (requisiteColumnDef) {
const filterCollectionAsync = requisiteColumnDef.filter!.collectionAsync;
const editorCollection = requisiteColumnDef.editor!.collection;
if (Array.isArray(editorCollection)) {
// add the new row to the grid
this.angularGrid.gridService.addItem(newRows[0]);
// then refresh the Editor "collection", we have 2 ways of doing it
// Push to the Editor "collection"
editorCollection.push({ value: lastRowIndex, label: lastRowIndex, prefix: 'Task' });
// or replace entire "collection"
// durationColumnDef.editor.collection = [...collection, ...[{ value: lastRowIndex, label: lastRowIndex }]];
// for the Filter only, we have a trigger an RxJS/Subject change with the new collection
// we do this because Filter(s) are shown at all time, while on Editor it's unnecessary since they are only shown when opening them
if (filterCollectionAsync instanceof Subject) {
filterCollectionAsync.next(editorCollection);
}
}
}
}, 250);
}
/**
* Delete last inserted row.
* Note that because Filter elements are always displayed on the screen, we need to tell the Filter,
* we do this via a Subject .next(), that it's collection got changed
* as for the Editor, there's nothing to do since the element is not shown and it will have latest collection next time it shows up
*/
deleteItem() {
const requisiteColumnDef = this.columnDefinitions.find((column: Column) => column.id === 'prerequisites');
if (requisiteColumnDef) {
const filterCollectionAsync = requisiteColumnDef.filter!.collectionAsync;
const filterCollection = requisiteColumnDef.filter!.collection;
if (Array.isArray(filterCollection)) {
// sort collection in descending order and take out last collection option
const selectCollectionObj = this.sortCollectionDescending(filterCollection).pop();
// then we will delete that item from the grid
this.angularGrid.gridService.deleteItemById(selectCollectionObj.value);
// for the Filter only, we have a trigger an RxJS/Subject change with the new collection
// we do this because Filter(s) are shown at all time, while on Editor it's unnecessary since they are only shown when opening them
if (filterCollectionAsync instanceof Subject) {
filterCollectionAsync.next(filterCollection);
}
}
}
}
sortCollectionDescending(collection: any[]) {
return collection.sort((item1, item2) => item1.value - item2.value);
}
mockData(itemCount: number, startingIndex = 0) {
// mock a dataset
const tempDataset = [];
for (let i = startingIndex; i < (startingIndex + itemCount); i++) {
const randomYear = 2000 + this.randomBetween(4, 15);
const randomFinishYear = (new Date().getFullYear() - 3) + Math.floor(Math.random() * 10); // use only years not lower than 3 years ago
const randomMonth = Math.floor(Math.random() * 11);
const randomDay = Math.floor((Math.random() * 29));
const randomPercent = Math.round(Math.random() * 100);
const randomFinish = new Date(randomFinishYear, (randomMonth + 1), randomDay);
tempDataset.push({
id: i,
title: 'Task ' + i,
duration: (i % 33 === 0) ? null : Math.round(Math.random() * 100) + '',
start: new Date(randomYear, randomMonth, randomDay),
percentComplete: randomPercent,
percentCompleteNumber: randomPercent,
finish: randomFinish < new Date() ? '' : randomFinish, // make sure the random date is earlier than today
effortDriven: (i % 5 === 0),
prerequisites: (i % 2 === 0) && i !== 0 && i < 12 ? [i, i - 1] : [],
countryOfOrigin: (i % 2) ? { code: 'CA', name: 'Canada' } : { code: 'US', name: 'United States' },
countryOfOriginName: (i % 2) ? 'Canada' : 'United States',
cityOfOrigin: (i % 2) ? 'Vancouver, BC, Canada' : 'Boston, MA, United States',
});
}
return tempDataset;
}
randomBetween(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1) + min);
}
onCellChanged(e: Event, args: any) {
this.updatedObject = args.item;
}
onCellClicked(e: Event, args: any) {
const metadata = this.angularGrid.gridService.getColumnFromEventArguments(args);
console.log(metadata);
if (metadata.columnDef.id === 'edit') {
this.alertWarning = `open a modal window to edit: ${metadata.dataContext.title}`;
// highlight the row, to customize the color, you can change the SASS variable $row-highlight-background-color
this.angularGrid.gridService.highlightRow(args.row, 1500);
// you could also select the row, when using "enableCellNavigation: true", it automatically selects the row
// this.angularGrid.gridService.setSelectedRow(args.row);
} else if (metadata.columnDef.id === 'delete') {
if (confirm('Are you sure?')) {
this.angularGrid.gridService.deleteItemById(metadata.dataContext.id);
}
}
}
onValidationError(e: Event, args: any) {
if (args.validationResults) {
alert(args.validationResults.msg);
}
}
changeAutoCommit() {
this.gridOptions.autoCommitEdit = !this.gridOptions.autoCommitEdit;
this.gridObj.setOptions({
autoCommitEdit: this.gridOptions.autoCommitEdit
});
return true;
}
dynamicallyAddTitleHeader() {
const newCol = {
id: `title${this.duplicateTitleHeaderCount++}`,
name: 'Title',
field: 'title',
editor: {
model: Editors.text,
required: true,
validator: myCustomTitleValidator, // use a custom validator
},
sortable: true, minWidth: 100, filterable: true,
};
// you can dynamically add your column to your column definitions
// and then use the spread operator [...cols] OR slice to force Angular to review the changes
this.columnDefinitions.push(newCol);
this.columnDefinitions = this.columnDefinitions.slice(); // or use spread operator [...cols]
// NOTE if you use an Extensions (Checkbox Selector, Row Detail, ...) that modifies the column definitions in any way
// you MUST use "getAllColumnDefinitions()" from the GridService, using this will be ALL columns including the 1st column that is created internally
// for example if you use the Checkbox Selector (row selection), you MUST use the code below
/*
const allColumns = this.angularGrid.gridService.getAllColumnDefinitions();
allColumns.push(newCol);
this.columnDefinitions = [...allColumns]; // (or use slice) reassign to column definitions for Angular to do dirty checking
*/
}
dynamicallyRemoveLastColumn() {
this.columnDefinitions.pop();
this.columnDefinitions = this.columnDefinitions.slice();
/*
// remove your column the full set of columns
// and use slice or spread [...] to trigger an Angular dirty change
allOriginalColumns.pop();
this.columnDefinitions = allOriginalColumns.slice();
*/
}
setAutoEdit(isAutoEdit: boolean) {
this.isAutoEdit = isAutoEdit;
this.gridObj.setOptions({ autoEdit: isAutoEdit }); // change the grid option dynamically
return true;
}
undo() {
const command = this._commandQueue.pop();
// const item = this.angularGrid.dataView.getItem(command.row);
if (command && SlickGlobalEditorLock.cancelCurrentEdit()) {
command.undo();
this.gridObj.gotoCell(command.row, command.cell, false);
}
}
}