Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 3150124

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
feat(core): add enableMouseWheelScrollHandler grid option
- this enables the use of the mousewheel scrolling event handler and that makes the mousewheel scroll to work from anywhere in the grid
1 parent 13809b4 commit 3150124

File tree

7 files changed

+31
-18
lines changed

7 files changed

+31
-18
lines changed

src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid-constructor.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,14 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
336336
expect(onAfterGridDestroyedSpy).toHaveBeenCalled();
337337
});
338338

339-
it('should load jQuery mousewheel when using a frozen grid', () => {
340-
const loadSpy = jest.spyOn(component, 'loadJqueryMousewheelDynamically');
339+
it('should load enable jquery mousewheel scrolling when using a frozen grid', () => {
340+
component.gridOptions.enableMouseWheelScrollHandler = undefined;
341341
component.gridOptions.frozenColumn = 3;
342342

343343
component.ngOnInit();
344344
component.ngAfterViewInit();
345345

346-
expect(loadSpy).toHaveBeenCalled();
346+
expect(component.gridOptions.enableMouseWheelScrollHandler).toBeTrue();
347347
});
348348

349349
describe('initialization method', () => {

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// only import the necessary core lib, each will be imported on demand when enabled (via require)
33
import 'jquery-ui-dist/jquery-ui';
44
import 'slickgrid/lib/jquery.event.drag-2.3.0';
5+
import 'slickgrid/lib/jquery.mousewheel';
56
import 'slickgrid/slick.core';
67
import 'slickgrid/slick.grid';
78
import 'slickgrid/slick.dataview';
@@ -272,10 +273,6 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
272273
}
273274

274275
ngOnInit(): void {
275-
if (this.gridOptions && (this.gridOptions.frozenColumn !== undefined && this.gridOptions.frozenColumn >= 0) || (this.gridOptions.frozenRow !== undefined && this.gridOptions.frozenRow >= 0)) {
276-
this.loadJqueryMousewheelDynamically();
277-
}
278-
279276
this.onBeforeGridCreate.emit(true);
280277
if (this.gridOptions && !this.gridOptions.enableAutoResize && (this._fixedHeight || this._fixedWidth)) {
281278
this.gridHeightString = `${this._fixedHeight}px`;
@@ -384,12 +381,6 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
384381
}
385382
}
386383

387-
loadJqueryMousewheelDynamically() {
388-
// load jQuery mousewheel only when using a frozen grid (this will make the mousewheel work on any side of the frozen container).
389-
// DO NOT USE with Row Detail
390-
require('slickgrid/lib/jquery.mousewheel');
391-
}
392-
393384
/**
394385
* On a Pagination changed, we will trigger a Grid State changed with the new pagination info
395386
* Also if we use Row Selection or the Checkbox Selector, we need to reset any selection
@@ -797,6 +788,11 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
797788
}
798789

799790
private initialization() {
791+
// when detecting a frozen grid, we'll automatically enable the mousewheel scroll handler so that we can scroll from both left/right frozen containers
792+
if (this.gridOptions && ((this.gridOptions.frozenRow !== undefined && this.gridOptions.frozenRow >= 0) || this.gridOptions.frozenColumn !== undefined && this.gridOptions.frozenColumn >= 0) && this.gridOptions.enableMouseWheelScrollHandler === undefined) {
793+
this.gridOptions.enableMouseWheelScrollHandler = true;
794+
}
795+
800796
// make sure the dataset is initialized (if not it will throw an error that it cannot getLength of null)
801797
this._dataset = this._dataset || [];
802798
this.gridOptions = this.mergeGridOptions(this.gridOptions);

src/app/modules/angular-slickgrid/extensions/__tests__/gridMenuExtension.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ describe('gridMenuExtension', () => {
607607

608608
expect(onCommandSpy).toHaveBeenCalled();
609609
expect(setColumnsSpy).toHaveBeenCalled();
610-
expect(setOptionsSpy).toHaveBeenCalledWith({ frozenColumn: -1 });
610+
expect(setOptionsSpy).toHaveBeenCalledWith({ frozenColumn: -1, enableMouseWheelScrollHandler: false });
611611
});
612612

613613
it('should call "clearFilters" and dataview refresh when the command triggered is "clear-filter"', () => {

src/app/modules/angular-slickgrid/extensions/__tests__/headerMenuExtension.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ describe('headerMenuExtension', () => {
416416
instance.onCommand.notify({ column: columnsMock[0], grid: gridStub, command: 'freeze-columns' }, new Slick.EventData(), gridStub);
417417

418418
expect(onCommandSpy).toHaveBeenCalled();
419-
expect(setOptionsSpy).toHaveBeenCalledWith({ frozenColumn: 0 });
419+
expect(setOptionsSpy).toHaveBeenCalledWith({ frozenColumn: 0, enableMouseWheelScrollHandler: true });
420420
expect(setColumnsSpy).toHaveBeenCalled();
421421
});
422422

@@ -429,7 +429,7 @@ describe('headerMenuExtension', () => {
429429
instance.onCommand.notify({ column: columnsMock[1], grid: gridStub, command: 'freeze-columns' }, new Slick.EventData(), gridStub);
430430

431431
expect(onCommandSpy).toHaveBeenCalled();
432-
expect(setOptionsSpy).toHaveBeenCalledWith({ frozenColumn: -1 });
432+
expect(setOptionsSpy).toHaveBeenCalledWith({ frozenColumn: -1, enableMouseWheelScrollHandler: true });
433433
expect(setColumnsSpy).toHaveBeenCalled();
434434
});
435435

src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ export class GridMenuExtension implements Extension {
375375
switch (args.command) {
376376
case 'clear-frozen-columns':
377377
const visibleColumns = [...this.sharedService.visibleColumns];
378-
this.sharedService.grid.setOptions({ frozenColumn: -1 });
378+
this.sharedService.grid.setOptions({ frozenColumn: -1, enableMouseWheelScrollHandler: false });
379379
if (Array.isArray(visibleColumns) && Array.isArray(this.sharedService.allColumns) && visibleColumns.length !== this.sharedService.allColumns.length) {
380380
this.sharedService.grid.setColumns(visibleColumns);
381381
}

src/app/modules/angular-slickgrid/extensions/headerMenuExtension.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,15 @@ export class HeaderMenuExtension implements Extension {
221221
if (this.sharedService.grid && this.sharedService.grid.getColumns && this.sharedService.grid.setColumns && this.sharedService.grid.getColumnIndex) {
222222
const columnIndex = this.sharedService.grid.getColumnIndex(column.id);
223223
const currentColumns = this.sharedService.grid.getColumns() as Column[];
224+
225+
// if we're using frozen columns, we need to readjust pinning when the new hidden column is on the left pinning container
226+
// we need to do this because SlickGrid freezes by index and has no knowledge of the columns themselves
227+
const frozenColumnIndex = this.sharedService.gridOptions.frozenColumn || -1;
228+
if (frozenColumnIndex >= 0 && frozenColumnIndex >= columnIndex) {
229+
this.sharedService.grid.setOptions({ frozenColumn: frozenColumnIndex - 1 });
230+
}
231+
232+
// then proceed with hiding the column in SlickGrid & trigger an event when done
224233
const visibleColumns = arrayRemoveItemByIndex(currentColumns, columnIndex);
225234
this.sharedService.visibleColumns = visibleColumns;
226235
this.sharedService.grid.setColumns(visibleColumns);
@@ -331,7 +340,7 @@ export class HeaderMenuExtension implements Extension {
331340
case 'freeze-columns':
332341
const visibleColumns = [...this.sharedService.visibleColumns];
333342
const columnPosition = visibleColumns.findIndex((col) => col.id === args.column.id);
334-
this.sharedService.grid.setOptions({ frozenColumn: columnPosition } as GridOption);
343+
this.sharedService.grid.setOptions({ frozenColumn: columnPosition, enableMouseWheelScrollHandler: true } as GridOption);
335344

336345
// to freeze columns, we need to take only the visible columns and we also need to use setColumns() when some of them are hidden
337346
// to make sure that we only use the visible columns, not doing this would show back some of the hidden columns

src/app/modules/angular-slickgrid/models/gridOption.interface.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ export interface GridOption {
249249
/** Do we want to enable a styling effect when hovering any row from the grid? */
250250
enableMouseHoverHighlightRow?: boolean;
251251

252+
/**
253+
* Do we want to always enable the mousewheel scroll handler?
254+
* In other words, do we want the mouse scrolling would work from anywhere.
255+
* Typically we should only enable it when using a Frozen/Pinned grid and if it does detect it to be a frozen grid,
256+
* then it will automatically enable the scroll handler if this flag was originally set to undefined (which it is by default unless the user specifically disabled it).
257+
*/
258+
enableMouseWheelScrollHandler?: boolean;
259+
252260
/** Do we want to enable pagination? Currently only works with a Backend Service API */
253261
enablePagination?: boolean;
254262

0 commit comments

Comments
 (0)