Skip to content

Commit e8f6197

Browse files
authored
fix: only assign CellRangeSelector when Hybrid has dragToSelect set (#1174)
1 parent 3403611 commit e8f6197

File tree

6 files changed

+24
-38
lines changed

6 files changed

+24
-38
lines changed

examples/example-master-detail-esm.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ <h2>View Source:</h2>
214214
data1 = mockMasterData();
215215
grid1 = new SlickGrid("#myGrid1", data1, columns1, gridOptions1);
216216
const selectionModel = new SlickHybridSelectionModel({
217-
selectionType: 'row-click',
218-
selectActiveRow: false
217+
selectionType: 'row',
219218
});
220219
grid1.setSelectionModel(selectionModel);
221220
grid1.init();

src/models/interactions.interface.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { DragPosition } from './drag.interface.js';
55

66
export interface InteractionBase {
77
destroy: () => void;
8-
pause?: () => void;
98
}
109
export interface ClassDetectElement {
1110
/** tag to be returned on match */

src/models/selectionModelOption.interface.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export type SelectionType =
88
| 'cell'
99
/** multiple row selection */
1010
| 'row'
11-
/** single row selection through row click */
12-
| 'row-click'
1311
/** mixed cell/row selection */
1412
| 'mixed';
1513

src/plugins/slick.hybridselectionmodel.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class SlickHybridSelectionModel implements SelectionModel {
4444
protected _prevSelectedRow?: number;
4545
protected _prevKeyDown = '';
4646
protected _ranges: SlickRange_[] = [];
47-
protected _selector: SlickCellRangeSelector_;
47+
protected _selector?: SlickCellRangeSelector_;
4848
protected _isRowMoveManagerHandler: any;
4949
protected _activeSelectionIsRow = false;
5050
protected _options: HybridSelectionModelOption;
@@ -62,15 +62,6 @@ export class SlickHybridSelectionModel implements SelectionModel {
6262

6363
constructor(options?: HybridSelectionModelOption) {
6464
this._options = Utils.extend(true, {}, this._defaults, options);
65-
66-
if (options === undefined || options.cellRangeSelector === undefined) {
67-
this._selector = new SlickCellRangeSelector({
68-
selectionCss: { border: '2px solid black' } as CSSStyleDeclaration,
69-
copyToSelectionCss: { border: '2px solid purple' } as CSSStyleDeclaration
70-
});
71-
} else {
72-
this._selector = options.cellRangeSelector;
73-
}
7465
}
7566

7667
// Region: Setup
@@ -90,14 +81,22 @@ export class SlickHybridSelectionModel implements SelectionModel {
9081
this._activeSelectionIsRow = true;
9182
}
9283

93-
if (!this._selector && this._options?.dragToSelect) {
84+
if (!this._selector && (!this._activeSelectionIsRow || (this._activeSelectionIsRow && this._options.dragToSelect))) {
9485
if (!SlickCellRangeDecorator) {
9586
throw new Error('Slick.CellRangeDecorator is required when option dragToSelect set to true');
9687
}
97-
this._selector = new SlickCellRangeSelector({
98-
selectionCss: { border: 'none' } as CSSStyleDeclaration,
99-
autoScroll: this._options?.autoScrollWhenDrag
100-
});
88+
this._selector = new SlickCellRangeSelector(
89+
this._options?.dragToSelect
90+
? {
91+
selectionCss: { border: 'none' } as CSSStyleDeclaration,
92+
autoScroll: this._options?.autoScrollWhenDrag,
93+
}
94+
: {
95+
selectionCss: { border: '2px solid gray' } as CSSStyleDeclaration,
96+
copyToSelectionCss: { border: '2px solid purple' } as CSSStyleDeclaration,
97+
}
98+
);
99+
this._options.cellRangeSelector = this._selector;
101100
}
102101

103102
if (grid.hasDataView()) {
@@ -473,7 +472,7 @@ export class SlickHybridSelectionModel implements SelectionModel {
473472
if (active >= 0 && active < this._grid.getDataLength()) {
474473
this._grid.scrollRowIntoView(active);
475474
const tempRanges = this.rowsToRanges(this.getRowsRange(top, bottom));
476-
this.setSelectedRanges(tempRanges, undefined, '');
475+
this.setSelectedRanges(tempRanges);
477476
}
478477

479478
e.preventDefault();
@@ -519,7 +518,7 @@ export class SlickHybridSelectionModel implements SelectionModel {
519518
}
520519

521520
const tempRanges = this.rowsToRanges(selection);
522-
this.setSelectedRanges(tempRanges, undefined, '');
521+
this.setSelectedRanges(tempRanges);
523522
e.stopImmediatePropagation();
524523

525524
return true;

src/slick.grid.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
978978
this._bindingEventService.bind(element, 'mouseout', this.handleCellMouseOut.bind(this) as EventListener);
979979
});
980980

981-
const isDraggable = this.selectionModel?.getOptions()?.selectionType !== 'row-click';
982-
if (Draggable && isDraggable) {
981+
if (Draggable) {
983982
this.slickDraggableInstance = Draggable({
984983
containerElement: this._container,
985984
allowDragFrom: `div.slick-cell, div.slick-cell *, div.${this.dragReplaceEl.cssClass}`,
@@ -1436,16 +1435,13 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
14361435
setSelectionModel(model: SelectionModel) {
14371436
if (this.selectionModel) {
14381437
this.selectionModel.onSelectedRangesChanged.unsubscribe(this.handleSelectedRangesChanged.bind(this));
1439-
this.selectionModel?.destroy();
1438+
this.selectionModel.destroy?.();
14401439
}
14411440

14421441
this.selectionModel = model;
14431442
if (this.selectionModel) {
14441443
this.selectionModel.init(this as unknown as SlickGridModel);
14451444
this.selectionModel.onSelectedRangesChanged.subscribe(this.handleSelectedRangesChanged.bind(this));
1446-
if (this.selectionModel.getOptions()?.selectionType === 'row-click' && this.slickDraggableInstance?.pause) {
1447-
this.slickDraggableInstance.pause(); // don't allow dragging (cell selection) when using row-click
1448-
}
14491445
}
14501446
}
14511447

src/slick.interactions.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const Utils = IIFE_ONLY ? Slick.Utils : Utils_;
3131
* @class Draggable
3232
*/
3333
export function Draggable(options: DraggableOption) {
34-
let isPaused = false;
3534
let { containerElement } = options;
3635
const { onDragInit, onDragStart, onDrag, onDragEnd, preventDragFromKeys } = options;
3736
let element: HTMLElement | null;
@@ -73,7 +72,7 @@ export function Draggable(options: DraggableOption) {
7372

7473
/** Do we want to prevent Drag events from happening (for example prevent onDrag when Ctrl key is pressed while dragging) */
7574
function preventDrag(event: MouseEvent | TouchEvent | KeyboardEvent) {
76-
let eventPrevented = isPaused;
75+
let eventPrevented = false;
7776
if (preventDragFromKeys) {
7877
preventDragFromKeys.forEach(key => {
7978
if ((event as KeyboardEvent)[key]) {
@@ -159,16 +158,11 @@ export function Draggable(options: DraggableOption) {
159158
}
160159
}
161160

162-
/** pause or stop the service */
163-
function pause() {
164-
isPaused = true;
165-
}
166-
167-
// initialize Slick.MouseWheel by attaching mousewheel event
161+
// initialize Draggable service by attaching mouse/touch events
168162
init();
169163

170164
// public API
171-
return { destroy, pause };
165+
return { destroy };
172166
}
173167

174168
/**
@@ -230,7 +224,7 @@ export function MouseWheel(options: MouseWheelOption) {
230224
}
231225
}
232226

233-
// initialize Slick.MouseWheel by attaching mousewheel event
227+
// initialize MouseWheel service by attaching mousewheel events
234228
init();
235229

236230
// public API
@@ -309,6 +303,7 @@ export function Resizable(options: ResizableOption) {
309303
document.body.removeEventListener('touchend', resizeEndHandler);
310304
}
311305

306+
// initialize Resizable service by attaching mouse/touch events
312307
init();
313308

314309
// public API

0 commit comments

Comments
 (0)