-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
slickGrid.ts
6308 lines (5452 loc) · 233 KB
/
slickGrid.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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import Sortable, { type SortableEvent } from 'sortablejs';
import DOMPurify from 'isomorphic-dompurify';
import { BindingEventService } from '@slickgrid-universal/binding';
import {
classNameToList,
createDomElement,
destroyAllElementProps,
emptyElement,
extend,
getInnerSize,
getOffset,
insertAfterElement,
isDefined,
isDefinedNumber,
isPrimitiveOrHTML,
} from '@slickgrid-universal/utils';
import {
type BasePubSub,
preClickClassName,
type SlickEditorLock,
SlickGlobalEditorLock,
SlickEvent,
SlickEventData,
SlickRange,
Utils,
} from './slickCore';
import { Draggable, MouseWheel, Resizable } from './slickInteractions';
import type { SelectionModel } from '../enums/index';
import type {
CellViewportRange,
Column,
ColumnSort,
CSSStyleDeclarationWritable,
CssStyleHash,
CustomDataView,
DOMEvent,
DragPosition,
DragRowMove,
EditController,
Editor,
EditorArguments,
EditorConstructor,
Formatter,
FormatterResultObject,
FormatterResultWithHtml,
FormatterResultWithText,
InteractionBase,
ItemMetadata,
GridOption as BaseGridOption,
MultiColumnSort,
OnActivateChangedOptionsEventArgs,
OnActiveCellChangedEventArgs,
OnAddNewRowEventArgs,
OnAfterSetColumnsEventArgs,
OnAutosizeColumnsEventArgs,
OnBeforeAppendCellEventArgs,
OnBeforeCellEditorDestroyEventArgs,
OnBeforeColumnsResizeEventArgs,
OnBeforeEditCellEventArgs,
OnBeforeFooterRowCellDestroyEventArgs,
OnBeforeHeaderCellDestroyEventArgs,
OnBeforeHeaderRowCellDestroyEventArgs,
OnBeforeSetColumnsEventArgs,
OnBeforeUpdateColumnsEventArgs,
OnCellChangeEventArgs,
OnCellCssStylesChangedEventArgs,
OnClickEventArgs,
OnColumnsDragEventArgs,
OnColumnsReorderedEventArgs,
OnColumnsResizedEventArgs,
OnColumnsResizeDblClickEventArgs,
OnCompositeEditorChangeEventArgs,
OnDblClickEventArgs,
OnFooterRowCellRenderedEventArgs,
OnFooterContextMenuEventArgs,
OnHeaderCellRenderedEventArgs,
OnFooterClickEventArgs,
OnHeaderClickEventArgs,
OnHeaderContextMenuEventArgs,
OnHeaderMouseEventArgs,
OnHeaderRowCellRenderedEventArgs,
OnKeyDownEventArgs,
OnRenderedEventArgs,
OnScrollEventArgs,
OnSelectedRowsChangedEventArgs,
OnSetOptionsEventArgs,
OnValidationErrorEventArgs,
PagingInfo,
SingleColumnSort,
SlickPlugin,
} from '../interfaces';
import type { SlickDataView } from './slickDataview';
/**
* @license
* (c) 2009-present Michael Leibman
* michael{dot}leibman{at}gmail{dot}com
* http://github.com/mleibman/slickgrid
*
* Distributed under MIT license.
* All rights reserved.
*
* SlickGrid v5.1.0
*
* NOTES:
* Cell/row DOM manipulations are done directly bypassing JS DOM manipulation methods.
* This increases the speed dramatically,
* but can only be done safely because there are no event handlers
* or data associated with any cell/row DOM nodes. Cell editors must make sure they implement .destroy()
* and do proper cleanup.
*/
// SlickGrid class implementation (available as SlickGrid)
interface RowCaching {
rowNode: HTMLElement[] | null,
cellColSpans: Array<number | '*'>;
cellNodesByColumnIdx: HTMLElement[];
cellRenderQueue: any[];
}
export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O extends BaseGridOption<C> = BaseGridOption<C>> {
// Public API
slickGridVersion = '5.7.1';
/** optional grid state clientId */
cid = '';
// Events
onActiveCellChanged: SlickEvent<OnActiveCellChangedEventArgs>;
onActiveCellPositionChanged: SlickEvent<{ grid: SlickGrid; }>;
onAddNewRow: SlickEvent<OnAddNewRowEventArgs>;
onAfterSetColumns: SlickEvent<OnAfterSetColumnsEventArgs>;
onAutosizeColumns: SlickEvent<OnAutosizeColumnsEventArgs>;
onBeforeAppendCell: SlickEvent<OnBeforeAppendCellEventArgs>;
onBeforeCellEditorDestroy: SlickEvent<OnBeforeCellEditorDestroyEventArgs>;
onBeforeColumnsResize: SlickEvent<OnBeforeColumnsResizeEventArgs>;
onBeforeDestroy: SlickEvent<{ grid: SlickGrid; }>;
onBeforeEditCell: SlickEvent<OnBeforeEditCellEventArgs>;
onBeforeFooterRowCellDestroy: SlickEvent<OnBeforeFooterRowCellDestroyEventArgs>;
onBeforeHeaderCellDestroy: SlickEvent<OnBeforeHeaderCellDestroyEventArgs>;
onBeforeHeaderRowCellDestroy: SlickEvent<OnBeforeHeaderRowCellDestroyEventArgs>;
onBeforeSetColumns: SlickEvent<OnBeforeSetColumnsEventArgs>;
onBeforeSort: SlickEvent<SingleColumnSort | MultiColumnSort>;
onBeforeUpdateColumns: SlickEvent<OnBeforeUpdateColumnsEventArgs>;
onCellChange: SlickEvent<OnCellChangeEventArgs>;
onCellCssStylesChanged: SlickEvent<OnCellCssStylesChangedEventArgs>;
onClick: SlickEvent<OnClickEventArgs>;
onColumnsReordered: SlickEvent<OnColumnsReorderedEventArgs>;
onColumnsDrag: SlickEvent<OnColumnsDragEventArgs>;
onColumnsResized: SlickEvent<OnColumnsResizedEventArgs>;
onColumnsResizeDblClick: SlickEvent<OnColumnsResizeDblClickEventArgs>;
onCompositeEditorChange: SlickEvent<OnCompositeEditorChangeEventArgs>;
onContextMenu: SlickEvent<{ grid: SlickGrid; }>;
onDrag: SlickEvent<DragRowMove>;
onDblClick: SlickEvent<OnDblClickEventArgs>;
onDragInit: SlickEvent<DragRowMove>;
onDragStart: SlickEvent<DragRowMove>;
onDragEnd: SlickEvent<DragRowMove>;
onFooterClick: SlickEvent<OnFooterClickEventArgs>;
onFooterContextMenu: SlickEvent<OnFooterContextMenuEventArgs>;
onFooterRowCellRendered: SlickEvent<OnFooterRowCellRenderedEventArgs>;
onHeaderCellRendered: SlickEvent<OnHeaderCellRenderedEventArgs>;
onHeaderClick: SlickEvent<OnHeaderClickEventArgs>;
onHeaderContextMenu: SlickEvent<OnHeaderContextMenuEventArgs>;
onHeaderMouseEnter: SlickEvent<OnHeaderMouseEventArgs>;
onHeaderMouseOver: SlickEvent<OnHeaderMouseEventArgs>;
onHeaderMouseOut: SlickEvent<OnHeaderMouseEventArgs>;
onHeaderMouseLeave: SlickEvent<OnHeaderMouseEventArgs>;
onHeaderRowCellRendered: SlickEvent<OnHeaderRowCellRenderedEventArgs>;
onHeaderRowMouseEnter: SlickEvent<OnHeaderMouseEventArgs>;
onHeaderRowMouseLeave: SlickEvent<OnHeaderMouseEventArgs>;
onHeaderRowMouseOver: SlickEvent<OnHeaderMouseEventArgs>;
onHeaderRowMouseOut: SlickEvent<OnHeaderMouseEventArgs>;
onKeyDown: SlickEvent<OnKeyDownEventArgs>;
onMouseEnter: SlickEvent<OnHeaderMouseEventArgs>;
onMouseLeave: SlickEvent<OnHeaderMouseEventArgs>;
onRendered: SlickEvent<OnRenderedEventArgs>;
onScroll: SlickEvent<OnScrollEventArgs>;
onSelectedRowsChanged: SlickEvent<OnSelectedRowsChangedEventArgs>;
onSetOptions: SlickEvent<OnSetOptionsEventArgs>;
onActivateChangedOptions: SlickEvent<OnActivateChangedOptionsEventArgs>;
onSort: SlickEvent<SingleColumnSort | MultiColumnSort>;
onValidationError: SlickEvent<OnValidationErrorEventArgs>;
onViewportChanged: SlickEvent<{ grid: SlickGrid; }>;
// ---
// protected variables
// shared across all grids on the page
protected scrollbarDimensions?: { height: number; width: number; };
protected maxSupportedCssHeight!: number; // browser's breaking point
protected canvas: HTMLCanvasElement | null = null;
protected canvas_context: CanvasRenderingContext2D | null = null;
// settings
protected _options!: O;
protected _defaults: BaseGridOption = {
alwaysShowVerticalScroll: false,
alwaysAllowHorizontalScroll: false,
explicitInitialization: false,
rowHeight: 25,
defaultColumnWidth: 80,
enableHtmlRendering: true,
enableAddRow: false,
leaveSpaceForNewRows: false,
editable: false,
autoEdit: true,
autoEditNewRow: true,
autoCommitEdit: false,
suppressActiveCellChangeOnEdit: false,
enableCellNavigation: true,
enableColumnReorder: true,
unorderableColumnCssClass: 'unorderable',
asyncEditorLoading: false,
asyncEditorLoadDelay: 100,
forceFitColumns: false,
enableAsyncPostRender: false,
asyncPostRenderDelay: 50,
enableAsyncPostRenderCleanup: false,
asyncPostRenderCleanupDelay: 40,
columnResizingDelay: 300,
nonce: '',
editorLock: SlickGlobalEditorLock,
showColumnHeader: true,
showHeaderRow: false,
headerRowHeight: 25,
createFooterRow: false,
showFooterRow: false,
footerRowHeight: 25,
createPreHeaderPanel: false,
showPreHeaderPanel: false,
preHeaderPanelHeight: 25,
showTopPanel: false,
topPanelHeight: 25,
formatterFactory: null,
editorFactory: null,
cellFlashingCssClass: 'flashing',
rowHighlightCssClass: 'highlight-animate',
rowHighlightDuration: 400,
selectedCellCssClass: 'selected',
multiSelect: true,
enableTextSelectionOnCells: false,
dataItemColumnValueExtractor: null,
frozenBottom: false,
frozenColumn: -1,
frozenRow: -1,
frozenRightViewportMinWidth: 100,
throwWhenFrozenNotAllViewable: false,
fullWidthRows: false,
multiColumnSort: false,
numberedMultiColumnSort: false,
tristateMultiColumnSort: false,
sortColNumberInSeparateSpan: false,
defaultFormatter: this.defaultFormatter,
forceSyncScrolling: false,
addNewRowCssClass: 'new-row',
preserveCopiedSelectionOnPaste: false,
showCellSelection: true,
viewportClass: undefined,
minRowBuffer: 3,
emulatePagingWhenScrolling: true, // when scrolling off bottom of viewport, place new row at top of viewport
editorCellNavOnLRKeys: false,
enableMouseWheelScrollHandler: true,
doPaging: true,
scrollRenderThrottling: 50,
suppressCssChangesOnHiddenInit: false,
ffMaxSupportedCssHeight: 6000000,
maxSupportedCssHeight: 1000000000,
sanitizer: undefined, // sanitize function
mixinDefaults: false,
shadowRoot: undefined
};
protected _columnDefaults = {
name: '',
headerCssClass: null,
defaultSortAsc: true,
focusable: true,
hidden: false,
minWidth: 30,
maxWidth: undefined,
rerenderOnResize: false,
reorderable: true,
resizable: true,
sortable: false,
selectable: true,
} as Partial<C>;
protected _columnResizeTimer?: NodeJS.Timeout;
protected _executionBlockTimer?: NodeJS.Timeout;
protected _flashCellTimer?: NodeJS.Timeout;
protected _highlightRowTimer?: NodeJS.Timeout;
// scroller
protected th!: number; // virtual height
protected h!: number; // real scrollable height
protected ph!: number; // page height
protected n!: number; // number of pages
protected cj!: number; // "jumpiness" coefficient
protected page = 0; // current page
protected offset = 0; // current page offset
protected vScrollDir = 1;
protected _bindingEventService = new BindingEventService();
protected initialized = false;
protected _container!: HTMLElement;
protected uid = `slickgrid_${Math.round(1000000 * Math.random())}`;
protected _focusSink!: HTMLDivElement;
protected _focusSink2!: HTMLDivElement;
protected _groupHeaders: HTMLDivElement[] = [];
protected _headerScroller: HTMLDivElement[] = [];
protected _headers: HTMLDivElement[] = [];
protected _headerRows!: HTMLDivElement[];
protected _headerRowScroller!: HTMLDivElement[];
protected _headerRowSpacerL!: HTMLDivElement;
protected _headerRowSpacerR!: HTMLDivElement;
protected _footerRow!: HTMLDivElement[];
protected _footerRowScroller!: HTMLDivElement[];
protected _footerRowSpacerL!: HTMLDivElement;
protected _footerRowSpacerR!: HTMLDivElement;
protected _preHeaderPanel!: HTMLDivElement;
protected _preHeaderPanelScroller!: HTMLDivElement;
protected _preHeaderPanelSpacer!: HTMLDivElement;
protected _preHeaderPanelR!: HTMLDivElement;
protected _preHeaderPanelScrollerR!: HTMLDivElement;
protected _preHeaderPanelSpacerR!: HTMLDivElement;
protected _topPanelScrollers!: HTMLDivElement[];
protected _topPanels!: HTMLDivElement[];
protected _viewport!: HTMLDivElement[];
protected _canvas!: HTMLDivElement[];
protected _style?: HTMLStyleElement;
protected _boundAncestors: HTMLElement[] = [];
protected stylesheet?: { cssRules: Array<{ selectorText: string; }>; rules: Array<{ selectorText: string; }>; } | null;
protected columnCssRulesL?: Array<{ selectorText: string; }>;
protected columnCssRulesR?: Array<{ selectorText: string; }>;
protected viewportH = 0;
protected viewportW = 0;
protected canvasWidth = 0;
protected canvasWidthL = 0;
protected canvasWidthR = 0;
protected headersWidth = 0;
protected headersWidthL = 0;
protected headersWidthR = 0;
protected viewportHasHScroll = false;
protected viewportHasVScroll = false;
protected headerColumnWidthDiff = 0;
protected headerColumnHeightDiff = 0; // border+padding
protected cellWidthDiff = 0;
protected cellHeightDiff = 0;
protected absoluteColumnMinWidth!: number;
protected hasFrozenRows = false;
protected frozenRowsHeight = 0;
protected actualFrozenRow = -1;
protected paneTopH = 0;
protected paneBottomH = 0;
protected viewportTopH = 0;
protected viewportBottomH = 0;
protected topPanelH = 0;
protected headerRowH = 0;
protected footerRowH = 0;
protected tabbingDirection = 1;
protected _activeCanvasNode!: HTMLDivElement;
protected _activeViewportNode!: HTMLDivElement;
protected activePosX!: number;
protected activeRow!: number;
protected activeCell!: number;
protected activeCellNode: HTMLDivElement | null = null;
protected currentEditor: Editor | null = null;
protected serializedEditorValue: any;
protected editController?: EditController;
protected rowsCache: Array<RowCaching> = {} as any;
protected renderedRows = 0;
protected numVisibleRows = 0;
protected prevScrollTop = 0;
protected scrollTop = 0;
protected lastRenderedScrollTop = 0;
protected lastRenderedScrollLeft = 0;
protected prevScrollLeft = 0;
protected scrollLeft = 0;
protected selectionModel?: SelectionModel;
protected selectedRows: number[] = [];
protected plugins: SlickPlugin[] = [];
protected cellCssClasses: CssStyleHash = {};
protected columnsById: Record<string, number> = {};
protected sortColumns: ColumnSort[] = [];
protected columnPosLeft: number[] = [];
protected columnPosRight: number[] = [];
protected pagingActive = false;
protected pagingIsLastPage = false;
protected scrollThrottle!: { enqueue: () => void; dequeue: () => void; };
// async call handles
protected h_editorLoader: any = null;
protected h_render = null;
protected h_postrender?: NodeJS.Timeout;
protected h_postrenderCleanup: any = null;
protected postProcessedRows: any = {};
protected postProcessToRow: number = null as any;
protected postProcessFromRow: number = null as any;
protected postProcessedCleanupQueue: Array<{
actionType: string;
groupId: number;
node: HTMLElement | HTMLElement[];
columnIdx?: number;
rowIdx?: number;
}> = [];
protected postProcessgroupId = 0;
// perf counters
protected counter_rows_rendered = 0;
protected counter_rows_removed = 0;
protected _paneHeaderL!: HTMLDivElement;
protected _paneHeaderR!: HTMLDivElement;
protected _paneTopL!: HTMLDivElement;
protected _paneTopR!: HTMLDivElement;
protected _paneBottomL!: HTMLDivElement;
protected _paneBottomR!: HTMLDivElement;
protected _headerScrollerL!: HTMLDivElement;
protected _headerScrollerR!: HTMLDivElement;
protected _headerL!: HTMLDivElement;
protected _headerR!: HTMLDivElement;
protected _groupHeadersL!: HTMLDivElement;
protected _groupHeadersR!: HTMLDivElement;
protected _headerRowScrollerL!: HTMLDivElement;
protected _headerRowScrollerR!: HTMLDivElement;
protected _footerRowScrollerL!: HTMLDivElement;
protected _footerRowScrollerR!: HTMLDivElement;
protected _headerRowL!: HTMLDivElement;
protected _headerRowR!: HTMLDivElement;
protected _footerRowL!: HTMLDivElement;
protected _footerRowR!: HTMLDivElement;
protected _topPanelScrollerL!: HTMLDivElement;
protected _topPanelScrollerR!: HTMLDivElement;
protected _topPanelL!: HTMLDivElement;
protected _topPanelR!: HTMLDivElement;
protected _viewportTopL!: HTMLDivElement;
protected _viewportTopR!: HTMLDivElement;
protected _viewportBottomL!: HTMLDivElement;
protected _viewportBottomR!: HTMLDivElement;
protected _canvasTopL!: HTMLDivElement;
protected _canvasTopR!: HTMLDivElement;
protected _canvasBottomL!: HTMLDivElement;
protected _canvasBottomR!: HTMLDivElement;
protected _viewportScrollContainerX!: HTMLDivElement;
protected _viewportScrollContainerY!: HTMLDivElement;
protected _headerScrollContainer!: HTMLDivElement;
protected _headerRowScrollContainer!: HTMLDivElement;
protected _footerRowScrollContainer!: HTMLDivElement;
// store css attributes if display:none is active in container or parent
protected cssShow = { position: 'absolute', visibility: 'hidden', display: 'block' };
protected _hiddenParents: HTMLElement[] = [];
protected oldProps: Array<Partial<CSSStyleDeclaration>> = [];
protected enforceFrozenRowHeightRecalc = false;
protected columnResizeDragging = false;
protected slickDraggableInstance: InteractionBase | null = null;
protected slickMouseWheelInstances: Array<InteractionBase> = [];
protected slickResizableInstances: Array<InteractionBase> = [];
protected sortableSideLeftInstance?: Sortable;
protected sortableSideRightInstance?: Sortable;
protected logMessageMaxCount = 30;
protected _pubSubService?: BasePubSub;
/**
* Creates a new instance of the grid.
* @class SlickGrid
* @constructor
* @param {Node} container - Container node to create the grid in.
* @param {Array|Object} data - An array of objects for databinding or an external DataView.
* @param {Array<C>} columns - An array of column definitions.
* @param {Object} [options] - Grid Options
* @param {Object} [externalPubSub] - optional External PubSub Service to use by SlickEvent
**/
constructor(protected readonly container: HTMLElement | string, protected data: CustomDataView<TData> | TData[], protected columns: C[], options: Partial<O>, protected readonly externalPubSub?: BasePubSub) {
this._container = typeof this.container === 'string'
? document.querySelector(this.container) as HTMLDivElement
: this.container;
if (!this._container) {
throw new Error(`SlickGrid requires a valid container, ${this.container} does not exist in the DOM.`);
}
this._pubSubService = externalPubSub;
this.onActiveCellChanged = new SlickEvent<OnActiveCellChangedEventArgs>('onActiveCellChanged', externalPubSub);
this.onActiveCellPositionChanged = new SlickEvent<{ grid: SlickGrid; }>('onActiveCellPositionChanged', externalPubSub);
this.onAddNewRow = new SlickEvent<OnAddNewRowEventArgs>('onAddNewRow', externalPubSub);
this.onAfterSetColumns = new SlickEvent<OnAfterSetColumnsEventArgs>('onAfterSetColumns', externalPubSub);
this.onAutosizeColumns = new SlickEvent<OnAutosizeColumnsEventArgs>('onAutosizeColumns', externalPubSub);
this.onBeforeAppendCell = new SlickEvent<OnBeforeAppendCellEventArgs>('onBeforeAppendCell', externalPubSub);
this.onBeforeCellEditorDestroy = new SlickEvent<OnBeforeCellEditorDestroyEventArgs>('onBeforeCellEditorDestroy', externalPubSub);
this.onBeforeColumnsResize = new SlickEvent<OnBeforeColumnsResizeEventArgs>('onBeforeColumnsResize', externalPubSub);
this.onBeforeDestroy = new SlickEvent<{ grid: SlickGrid; }>('onBeforeDestroy', externalPubSub);
this.onBeforeEditCell = new SlickEvent<OnBeforeEditCellEventArgs>('onBeforeEditCell', externalPubSub);
this.onBeforeFooterRowCellDestroy = new SlickEvent<OnBeforeFooterRowCellDestroyEventArgs>('onBeforeFooterRowCellDestroy', externalPubSub);
this.onBeforeHeaderCellDestroy = new SlickEvent<OnBeforeHeaderCellDestroyEventArgs>('onBeforeHeaderCellDestroy', externalPubSub);
this.onBeforeHeaderRowCellDestroy = new SlickEvent<OnBeforeHeaderRowCellDestroyEventArgs>('onBeforeHeaderRowCellDestroy', externalPubSub);
this.onBeforeSetColumns = new SlickEvent<OnBeforeSetColumnsEventArgs>('onBeforeSetColumns', externalPubSub);
this.onBeforeSort = new SlickEvent<SingleColumnSort | MultiColumnSort>('onBeforeSort', externalPubSub);
this.onBeforeUpdateColumns = new SlickEvent<OnBeforeUpdateColumnsEventArgs>('onBeforeUpdateColumns', externalPubSub);
this.onCellChange = new SlickEvent<OnCellChangeEventArgs>('onCellChange', externalPubSub);
this.onCellCssStylesChanged = new SlickEvent<OnCellCssStylesChangedEventArgs>('onCellCssStylesChanged', externalPubSub);
this.onClick = new SlickEvent<OnClickEventArgs>('onClick', externalPubSub);
this.onColumnsReordered = new SlickEvent<OnColumnsReorderedEventArgs>('onColumnsReordered', externalPubSub);
this.onColumnsDrag = new SlickEvent<OnColumnsDragEventArgs>('onColumnsDrag', externalPubSub);
this.onColumnsResized = new SlickEvent<OnColumnsResizedEventArgs>('onColumnsResized', externalPubSub);
this.onColumnsResizeDblClick = new SlickEvent<OnColumnsResizeDblClickEventArgs>('onColumnsResizeDblClick', externalPubSub);
this.onCompositeEditorChange = new SlickEvent<OnCompositeEditorChangeEventArgs>('onCompositeEditorChange', externalPubSub);
this.onContextMenu = new SlickEvent<{ grid: SlickGrid; }>('onContextMenu', externalPubSub);
this.onDrag = new SlickEvent<DragRowMove>('onDrag', externalPubSub);
this.onDblClick = new SlickEvent<OnDblClickEventArgs>('onDblClick', externalPubSub);
this.onDragInit = new SlickEvent<DragRowMove>('onDragInit', externalPubSub);
this.onDragStart = new SlickEvent<DragRowMove>('onDragStart', externalPubSub);
this.onDragEnd = new SlickEvent<DragRowMove>('onDragEnd', externalPubSub);
this.onFooterClick = new SlickEvent<OnFooterClickEventArgs>('onFooterClick', externalPubSub);
this.onFooterContextMenu = new SlickEvent<OnFooterContextMenuEventArgs>('onFooterContextMenu', externalPubSub);
this.onFooterRowCellRendered = new SlickEvent<OnFooterRowCellRenderedEventArgs>('onFooterRowCellRendered', externalPubSub);
this.onHeaderCellRendered = new SlickEvent<OnHeaderCellRenderedEventArgs>('onHeaderCellRendered', externalPubSub);
this.onHeaderClick = new SlickEvent<OnHeaderClickEventArgs>('onHeaderClick', externalPubSub);
this.onHeaderContextMenu = new SlickEvent<OnHeaderContextMenuEventArgs>('onHeaderContextMenu', externalPubSub);
this.onHeaderMouseEnter = new SlickEvent<OnHeaderMouseEventArgs>('onHeaderMouseEnter', externalPubSub);
this.onHeaderMouseOver = new SlickEvent<OnHeaderMouseEventArgs>('onHeaderMouseOver', externalPubSub);
this.onHeaderMouseOut = new SlickEvent<OnHeaderMouseEventArgs>('onHeaderMouseOut', externalPubSub);
this.onHeaderMouseLeave = new SlickEvent<OnHeaderMouseEventArgs>('onHeaderMouseLeave', externalPubSub);
this.onHeaderRowMouseOver = new SlickEvent<OnHeaderMouseEventArgs>('onHeaderRowMouseOver', externalPubSub);
this.onHeaderRowMouseOut = new SlickEvent<OnHeaderMouseEventArgs>('onHeaderRowMouseOut', externalPubSub);
this.onHeaderRowCellRendered = new SlickEvent<OnHeaderRowCellRenderedEventArgs>('onHeaderRowCellRendered', externalPubSub);
this.onHeaderRowMouseEnter = new SlickEvent<OnHeaderMouseEventArgs>('onHeaderRowMouseEnter', externalPubSub);
this.onHeaderRowMouseLeave = new SlickEvent<OnHeaderMouseEventArgs>('onHeaderRowMouseLeave', externalPubSub);
this.onKeyDown = new SlickEvent<OnKeyDownEventArgs>('onKeyDown', externalPubSub);
this.onMouseEnter = new SlickEvent<OnHeaderMouseEventArgs>('onMouseEnter', externalPubSub);
this.onMouseLeave = new SlickEvent<OnHeaderMouseEventArgs>('onMouseLeave', externalPubSub);
this.onRendered = new SlickEvent<OnRenderedEventArgs>('onRendered', externalPubSub);
this.onScroll = new SlickEvent<OnScrollEventArgs>('onScroll', externalPubSub);
this.onSelectedRowsChanged = new SlickEvent<OnSelectedRowsChangedEventArgs>('onSelectedRowsChanged', externalPubSub);
this.onSetOptions = new SlickEvent<OnSetOptionsEventArgs>('onSetOptions', externalPubSub);
this.onActivateChangedOptions = new SlickEvent<OnActivateChangedOptionsEventArgs>('onActivateChangedOptions', externalPubSub);
this.onSort = new SlickEvent<SingleColumnSort | MultiColumnSort>('onSort', externalPubSub);
this.onValidationError = new SlickEvent<OnValidationErrorEventArgs>('onValidationError', externalPubSub);
this.onViewportChanged = new SlickEvent<{ grid: SlickGrid; }>('onViewportChanged', externalPubSub);
this.initialize(options);
}
// Initialization
/** Initializes the grid. */
init() {
this.finishInitialization();
}
/**
* Apply HTML code by 3 different ways depending on what is provided as input and what options are enabled.
* 1. value is an HTMLElement or DocumentFragment, then first empty the target and simply append the HTML to the target element.
* 2. value is string and `enableHtmlRendering` is enabled, then use `target.innerHTML = value;`
* 3. value is string and `enableHtmlRendering` is disabled, then use `target.textContent = value;`
* @param target - target element to apply to
* @param val - input value can be either a string or an HTMLElement
* @param options -
* `emptyTarget`, defaults to true, will empty the target.
* `sanitizerOptions` is to provide extra options when using `innerHTML` and the sanitizer.
* `skipEmptyReassignment`, defaults to true, when enabled it will not try to reapply an empty value when the target is already empty
*/
applyHtmlCode(target: HTMLElement, val: string | boolean | number | HTMLElement | DocumentFragment = '', options?: { emptyTarget?: boolean; sanitizerOptions?: unknown; skipEmptyReassignment?: boolean; }) {
if (target) {
if (val instanceof HTMLElement || val instanceof DocumentFragment) {
// first empty target and then append new HTML element
const emptyTarget = options?.emptyTarget !== false;
if (emptyTarget) {
emptyElement(target);
}
target.appendChild(val);
} else {
// when it's already empty and we try to reassign empty, it's probably ok to skip the assignment
const skipEmptyReassignment = options?.skipEmptyReassignment !== false;
if (skipEmptyReassignment && !isDefined(val) && !target.innerHTML) {
return; // same result, just skip it
}
let sanitizedText = val;
if (typeof sanitizedText === 'number' || typeof sanitizedText === 'boolean') {
target.textContent = String(sanitizedText);
} else {
if (typeof this._options?.sanitizer === 'function') {
sanitizedText = this._options.sanitizer(val as string);
} else if (typeof DOMPurify?.sanitize === 'function') {
const purifyOptions = (options?.sanitizerOptions ?? this._options.sanitizerOptions ?? { ADD_ATTR: ['level'], RETURN_TRUSTED_TYPE: true }) as DOMPurify.Config;
sanitizedText = DOMPurify.sanitize(val as string, purifyOptions) as unknown as string;
}
// apply HTML when enableHtmlRendering is enabled but make sure we do have a value (without a value, it will simply use `textContent` to clear text content)
if (this._options.enableHtmlRendering && sanitizedText) {
target.innerHTML = sanitizedText;
} else {
target.textContent = sanitizedText;
}
}
}
}
}
protected initialize(options: Partial<O>) {
// calculate these only once and share between grid instances
if (options?.mixinDefaults) {
// use provided options and then assign defaults
if (!this._options) { this._options = options as O; }
Utils.applyDefaults(this._options, this._defaults);
} else {
this._options = extend<O>(true, {}, this._defaults, options);
}
this.scrollThrottle = this.actionThrottle(this.render.bind(this), this._options.scrollRenderThrottling as number);
this.maxSupportedCssHeight = this.maxSupportedCssHeight || this.getMaxSupportedCssHeight();
this.validateAndEnforceOptions();
this._columnDefaults.width = this._options.defaultColumnWidth;
if (!this._options.suppressCssChangesOnHiddenInit) {
this.cacheCssForHiddenInit();
}
this.updateColumnProps();
// validate loaded JavaScript modules against requested options
/* istanbul ignore if */
if (this._options.enableColumnReorder && (!Sortable || !Sortable.create)) {
throw new Error('SlickGrid requires Sortable.js module to be loaded');
}
this.editController = {
commitCurrentEdit: this.commitCurrentEdit.bind(this),
cancelCurrentEdit: this.cancelCurrentEdit.bind(this),
};
emptyElement(this._container);
this._container.style.overflow = 'hidden';
this._container.style.outline = String(0);
this._container.classList.add(this.uid);
this._container.classList.add('ui-widget');
this._container.setAttribute('role', 'grid');
const containerStyles = window.getComputedStyle(this._container);
if (!(/relative|absolute|fixed/).test(containerStyles.position)) {
this._container.style.position = 'relative';
}
this._focusSink = createDomElement('div', { tabIndex: 0, style: { position: 'fixed', width: '0px', height: '0px', top: '0px', left: '0px', outline: '0px' } }, this._container);
// Containers used for scrolling frozen columns and rows
this._paneHeaderL = createDomElement('div', { className: 'slick-pane slick-pane-header slick-pane-left', tabIndex: 0 }, this._container);
this._paneHeaderR = createDomElement('div', { className: 'slick-pane slick-pane-header slick-pane-right', tabIndex: 0 }, this._container);
this._paneTopL = createDomElement('div', { className: 'slick-pane slick-pane-top slick-pane-left', tabIndex: 0 }, this._container);
this._paneTopR = createDomElement('div', { className: 'slick-pane slick-pane-top slick-pane-right', tabIndex: 0 }, this._container);
this._paneBottomL = createDomElement('div', { className: 'slick-pane slick-pane-bottom slick-pane-left', tabIndex: 0 }, this._container);
this._paneBottomR = createDomElement('div', { className: 'slick-pane slick-pane-bottom slick-pane-right', tabIndex: 0 }, this._container);
if (this._options.createPreHeaderPanel) {
this._preHeaderPanelScroller = createDomElement('div', { className: 'slick-preheader-panel ui-state-default slick-state-default', style: { overflow: 'hidden', position: 'relative' } }, this._paneHeaderL);
this._preHeaderPanelScroller.appendChild(document.createElement('div'));
this._preHeaderPanel = createDomElement('div', null, this._preHeaderPanelScroller);
this._preHeaderPanelSpacer = createDomElement('div', { style: { display: 'block', height: '1px', position: 'absolute', top: '0px', left: '0px' } }, this._preHeaderPanelScroller);
this._preHeaderPanelScrollerR = createDomElement('div', { className: 'slick-preheader-panel ui-state-default slick-state-default', style: { overflow: 'hidden', position: 'relative' } }, this._paneHeaderR);
this._preHeaderPanelR = createDomElement('div', null, this._preHeaderPanelScrollerR);
this._preHeaderPanelSpacerR = createDomElement('div', { style: { display: 'block', height: '1px', position: 'absolute', top: '0px', left: '0px' } }, this._preHeaderPanelScrollerR);
if (!this._options.showPreHeaderPanel) {
Utils.hide(this._preHeaderPanelScroller);
Utils.hide(this._preHeaderPanelScrollerR);
}
}
// Append the header scroller containers
this._headerScrollerL = createDomElement('div', { className: 'slick-header ui-state-default slick-state-default slick-header-left' }, this._paneHeaderL);
this._headerScrollerR = createDomElement('div', { className: 'slick-header ui-state-default slick-state-default slick-header-right' }, this._paneHeaderR);
// Cache the header scroller containers
this._headerScroller.push(this._headerScrollerL);
this._headerScroller.push(this._headerScrollerR);
// Append the columnn containers to the headers
this._headerL = createDomElement('div', { className: 'slick-header-columns slick-header-columns-left', style: { left: '-1000px' } }, this._headerScrollerL);
this._headerR = createDomElement('div', { className: 'slick-header-columns slick-header-columns-right', style: { left: '-1000px' } }, this._headerScrollerR);
// Cache the header columns
this._headers = [this._headerL, this._headerR];
this._headerRowScrollerL = createDomElement('div', { className: 'slick-headerrow ui-state-default slick-state-default' }, this._paneTopL);
this._headerRowScrollerR = createDomElement('div', { className: 'slick-headerrow ui-state-default slick-state-default' }, this._paneTopR);
this._headerRowScroller = [this._headerRowScrollerL, this._headerRowScrollerR];
this._headerRowSpacerL = createDomElement('div', { style: { display: 'block', height: '1px', position: 'absolute', top: '0px', left: '0px' } }, this._headerRowScrollerL);
this._headerRowSpacerR = createDomElement('div', { style: { display: 'block', height: '1px', position: 'absolute', top: '0px', left: '0px' } }, this._headerRowScrollerR);
this._headerRowL = createDomElement('div', { className: 'slick-headerrow-columns slick-headerrow-columns-left' }, this._headerRowScrollerL);
this._headerRowR = createDomElement('div', { className: 'slick-headerrow-columns slick-headerrow-columns-right' }, this._headerRowScrollerR);
this._headerRows = [this._headerRowL, this._headerRowR];
// Append the top panel scroller
this._topPanelScrollerL = createDomElement('div', { className: 'slick-top-panel-scroller ui-state-default slick-state-default' }, this._paneTopL);
this._topPanelScrollerR = createDomElement('div', { className: 'slick-top-panel-scroller ui-state-default slick-state-default' }, this._paneTopR);
this._topPanelScrollers = [this._topPanelScrollerL, this._topPanelScrollerR];
// Append the top panel
this._topPanelL = createDomElement('div', { className: 'slick-top-panel', style: { width: '10000px' } }, this._topPanelScrollerL);
this._topPanelR = createDomElement('div', { className: 'slick-top-panel', style: { width: '10000px' } }, this._topPanelScrollerR);
this._topPanels = [this._topPanelL, this._topPanelR];
if (!this._options.showColumnHeader) {
this._headerScroller.forEach((el) => {
Utils.hide(el);
});
}
if (!this._options.showTopPanel) {
this._topPanelScrollers.forEach((scroller) => {
Utils.hide(scroller);
});
}
if (!this._options.showHeaderRow) {
this._headerRowScroller.forEach((scroller) => {
Utils.hide(scroller);
});
}
// Append the viewport containers
this._viewportTopL = createDomElement('div', { className: 'slick-viewport slick-viewport-top slick-viewport-left', tabIndex: 0 }, this._paneTopL);
this._viewportTopR = createDomElement('div', { className: 'slick-viewport slick-viewport-top slick-viewport-right', tabIndex: 0 }, this._paneTopR);
this._viewportBottomL = createDomElement('div', { className: 'slick-viewport slick-viewport-bottom slick-viewport-left', tabIndex: 0 }, this._paneBottomL);
this._viewportBottomR = createDomElement('div', { className: 'slick-viewport slick-viewport-bottom slick-viewport-right', tabIndex: 0 }, this._paneBottomR);
// Cache the viewports
this._viewport = [this._viewportTopL, this._viewportTopR, this._viewportBottomL, this._viewportBottomR];
if (this._options.viewportClass) {
this._viewport.forEach((view) => {
view.classList.add(...classNameToList(this._options.viewportClass));
});
}
// Default the active viewport to the top left
this._activeViewportNode = this._viewportTopL;
// Append the canvas containers
this._canvasTopL = createDomElement('div', { className: 'grid-canvas grid-canvas-top grid-canvas-left', tabIndex: 0 }, this._viewportTopL);
this._canvasTopR = createDomElement('div', { className: 'grid-canvas grid-canvas-top grid-canvas-right', tabIndex: 0 }, this._viewportTopR);
this._canvasBottomL = createDomElement('div', { className: 'grid-canvas grid-canvas-bottom grid-canvas-left', tabIndex: 0 }, this._viewportBottomL);
this._canvasBottomR = createDomElement('div', { className: 'grid-canvas grid-canvas-bottom grid-canvas-right', tabIndex: 0 }, this._viewportBottomR);
// Cache the canvases
this._canvas = [this._canvasTopL, this._canvasTopR, this._canvasBottomL, this._canvasBottomR];
this.scrollbarDimensions = this.scrollbarDimensions || this.measureScrollbar();
// Default the active canvas to the top left
this._activeCanvasNode = this._canvasTopL;
// pre-header
if (this._preHeaderPanelSpacer) {
Utils.width(this._preHeaderPanelSpacer, this.getCanvasWidth() + this.scrollbarDimensions.width);
}
this._headers.forEach((el) => {
Utils.width(el, this.getHeadersWidth());
});
Utils.width(this._headerRowSpacerL, this.getCanvasWidth() + this.scrollbarDimensions.width);
Utils.width(this._headerRowSpacerR, this.getCanvasWidth() + this.scrollbarDimensions.width);
// footer Row
if (this._options.createFooterRow) {
this._footerRowScrollerR = createDomElement('div', { className: 'slick-footerrow ui-state-default slick-state-default' }, this._paneTopR);
this._footerRowScrollerL = createDomElement('div', { className: 'slick-footerrow ui-state-default slick-state-default' }, this._paneTopL);
this._footerRowScroller = [this._footerRowScrollerL, this._footerRowScrollerR];
this._footerRowSpacerL = createDomElement('div', { style: { display: 'block', height: '1px', position: 'absolute', top: '0px', left: '0px' } }, this._footerRowScrollerL);
Utils.width(this._footerRowSpacerL, this.getCanvasWidth() + this.scrollbarDimensions.width);
this._footerRowSpacerR = createDomElement('div', { style: { display: 'block', height: '1px', position: 'absolute', top: '0px', left: '0px' } }, this._footerRowScrollerR);
Utils.width(this._footerRowSpacerR, this.getCanvasWidth() + this.scrollbarDimensions.width);
this._footerRowL = createDomElement('div', { className: 'slick-footerrow-columns slick-footerrow-columns-left' }, this._footerRowScrollerL);
this._footerRowR = createDomElement('div', { className: 'slick-footerrow-columns slick-footerrow-columns-right' }, this._footerRowScrollerR);
this._footerRow = [this._footerRowL, this._footerRowR];
if (!this._options.showFooterRow) {
this._footerRowScroller.forEach((scroller) => {
Utils.hide(scroller);
});
}
}
this._focusSink2 = this._focusSink.cloneNode(true) as HTMLDivElement;
this._container.appendChild(this._focusSink2);
if (!this._options.explicitInitialization) {
this.finishInitialization();
}
}
protected finishInitialization() {
if (!this.initialized) {
this.initialized = true;
this.getViewportWidth();
this.getViewportHeight();
// header columns and cells may have different padding/border skewing width calculations (box-sizing, hello?)
// calculate the diff so we can set consistent sizes
this.measureCellPaddingAndBorder();
// for usability reasons, all text selection in SlickGrid are disabled
// with the exception of input and textarea elements (selection must
// be enabled there so that editors work as expected); note that
// selection in grid cells (grid body) is already unavailable in
// all browsers except IE
this.disableSelection(this._headers); // disable all text selection in header (including input and textarea)
if (!this._options.enableTextSelectionOnCells) {
// disable text selection in grid cells except in input and textarea elements
// (this is IE-specific, because selectstart event will only fire in IE)
this._viewport.forEach((view) => {
this._bindingEventService.bind(view, 'selectstart', (event: Event) => {
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) {
return;
}
});
});
}
this.setFrozenOptions();
this.setPaneVisibility();
this.setScroller();
this.setOverflow();
this.updateColumnCaches();
this.createColumnHeaders();
this.createColumnFooter();
this.setupColumnSort();
this.createCssRules();
this.resizeCanvas();
this.bindAncestorScrollEvents();
this._bindingEventService.bind(this._container, 'resize', this.resizeCanvas.bind(this));
this._viewport.forEach((view) => {
this._bindingEventService.bind(view, 'scroll', this.handleScroll.bind(this));
});
if (this._options.enableMouseWheelScrollHandler) {
this._viewport.forEach((view) => {
this.slickMouseWheelInstances.push(MouseWheel({
element: view,
onMouseWheel: this.handleMouseWheel.bind(this)
}));
});
}
this._headerScroller.forEach((el) => {
this._bindingEventService.bind(el, 'contextmenu', this.handleHeaderContextMenu.bind(this) as EventListener);
this._bindingEventService.bind(el, 'click', this.handleHeaderClick.bind(this) as EventListener);
});
this._headerRowScroller.forEach((scroller) => {
this._bindingEventService.bind(scroller, 'scroll', this.handleHeaderRowScroll.bind(this) as EventListener);
});
if (this._options.createFooterRow) {
this._footerRow.forEach((footer) => {
this._bindingEventService.bind(footer, 'contextmenu', this.handleFooterContextMenu.bind(this) as EventListener);
this._bindingEventService.bind(footer, 'click', this.handleFooterClick.bind(this) as EventListener);
});
this._footerRowScroller.forEach((scroller) => {
this._bindingEventService.bind(scroller, 'scroll', this.handleFooterRowScroll.bind(this) as EventListener);
});
}
if (this._options.createPreHeaderPanel) {
this._bindingEventService.bind(this._preHeaderPanelScroller, 'scroll', this.handlePreHeaderPanelScroll.bind(this) as EventListener);
}
this._bindingEventService.bind(this._focusSink, 'keydown', this.handleKeyDown.bind(this) as EventListener);
this._bindingEventService.bind(this._focusSink2, 'keydown', this.handleKeyDown.bind(this) as EventListener);
this._canvas.forEach((element) => {
this._bindingEventService.bind(element, 'keydown', this.handleKeyDown.bind(this) as EventListener);
this._bindingEventService.bind(element, 'click', this.handleClick.bind(this) as EventListener);
this._bindingEventService.bind(element, 'dblclick', this.handleDblClick.bind(this) as EventListener);
this._bindingEventService.bind(element, 'contextmenu', this.handleContextMenu.bind(this) as EventListener);
this._bindingEventService.bind(element, 'mouseover', this.handleCellMouseOver.bind(this) as EventListener);
this._bindingEventService.bind(element, 'mouseout', this.handleCellMouseOut.bind(this) as EventListener);
});
if (Draggable) {
this.slickDraggableInstance = Draggable({
containerElement: this._container,
allowDragFrom: 'div.slick-cell',
// the slick cell parent must always contain `.dnd` and/or `.cell-reorder` class to be identified as draggable
allowDragFromClosest: 'div.slick-cell.dnd, div.slick-cell.cell-reorder',
onDragInit: this.handleDragInit.bind(this),
onDragStart: this.handleDragStart.bind(this),
onDrag: this.handleDrag.bind(this),
onDragEnd: this.handleDragEnd.bind(this)
});
}
if (!this._options.suppressCssChangesOnHiddenInit) {
this.restoreCssFromHiddenInit();
}
}
}
/** handles "display:none" on container or container parents, related to issue: https://github.com/6pac/SlickGrid/issues/568 */
cacheCssForHiddenInit() {
this._hiddenParents = Utils.parents(this._container, ':hidden') as HTMLElement[];
this._hiddenParents.forEach(el => {
const old: Partial<CSSStyleDeclaration> = {};
Object.keys(this.cssShow).forEach(name => {
if (this.cssShow) {
old[name as any] = el.style[name as 'position' | 'visibility' | 'display'];
el.style[name as any] = this.cssShow[name as 'position' | 'visibility' | 'display'];
}
});
this.oldProps.push(old);
});
}
restoreCssFromHiddenInit() {
// finish handle display:none on container or container parents
// - put values back the way they were
let i = 0;
if (this._hiddenParents) {
this._hiddenParents.forEach(el => {
const old = this.oldProps[i++];
Object.keys(this.cssShow).forEach(name => {
if (this.cssShow) {
el.style[name as CSSStyleDeclarationWritable] = (old as any)[name];
}
});
});
}
}
protected hasFrozenColumns() {
return this._options.frozenColumn! > -1;
}
/** Register an external Plugin */
registerPlugin<T extends SlickPlugin>(plugin: T) {
this.plugins.unshift(plugin);
plugin.init(this as unknown as SlickGrid);
}
/** Unregister (destroy) an external Plugin */
unregisterPlugin(plugin: SlickPlugin) {
for (let i = this.plugins.length; i >= 0; i--) {
if (this.plugins[i] === plugin) {
this.plugins[i]?.destroy();
this.plugins.splice(i, 1);
break;
}
}
}
/** Get a Plugin (addon) by its name */
getPluginByName<P extends SlickPlugin | undefined = undefined>(name: string) {
for (let i = this.plugins.length - 1; i >= 0; i--) {
if (this.plugins[i]?.pluginName === name) {
return this.plugins[i] as P;
}
}
return undefined;
}
getPubSubService(): BasePubSub | undefined {
return this._pubSubService;
}
/**
* Unregisters a current selection model and registers a new one. See the definition of SelectionModel for more information.
* @param {Object} selectionModel A SelectionModel.
*/
setSelectionModel(model: SelectionModel) {
if (this.selectionModel) {
this.selectionModel.onSelectedRangesChanged.unsubscribe(this.handleSelectedRangesChanged.bind(this));
if (this.selectionModel.destroy) {
this.selectionModel.destroy();