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

Commit dd76dd7

Browse files
authored
Merge pull request #641 from ghiscoding/feat/mousewheel-scroll-only-frozen-grid
feat(core): add enableMouseWheelScrollHandler grid option
2 parents 13809b4 + 638422b commit dd76dd7

File tree

10 files changed

+38
-33
lines changed

10 files changed

+38
-33
lines changed

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
}
100100
},
101101
"dependencies": {
102-
"dompurify": "^2.0.12",
102+
"dompurify": "^2.2.2",
103103
"excel-builder-webpacker": "^1.0.6",
104104
"flatpickr": "^4.6.6",
105105
"font-awesome": "^4.7.0",
@@ -108,21 +108,21 @@
108108
"lodash.isequal": "^4.5.0",
109109
"moment-mini": "^2.24.0",
110110
"rxjs": "^6.3.3",
111-
"slickgrid": "^2.4.31",
111+
"slickgrid": "^2.4.32",
112112
"text-encoding-utf-8": "^1.0.2"
113113
},
114114
"peerDependencies": {
115115
"@ngx-translate/core": ">=11.0.1",
116116
"@ngx-translate/http-loader": ">=4.0.0"
117117
},
118118
"devDependencies": {
119-
"@angular-builders/jest": "^7.4.2",
119+
"@angular-builders/jest": "^7.4.4",
120120
"@angular-devkit/build-angular": "~0.803.29",
121121
"@angular/animations": "^8.2.14",
122122
"@angular/cli": "^8.3.29",
123123
"@angular/common": "^8.2.14",
124-
"@angular/compiler": "8.2.14",
125-
"@angular/compiler-cli": "8.2.14",
124+
"@angular/compiler": "^8.2.14",
125+
"@angular/compiler-cli": "^8.2.14",
126126
"@angular/core": "^8.2.14",
127127
"@angular/forms": "^8.2.14",
128128
"@angular/language-service": "^8.2.14",
@@ -141,14 +141,14 @@
141141
"@types/text-encoding-utf-8": "^1.0.1",
142142
"babel-jest": "^24.9.0",
143143
"bootstrap": "3.4.1",
144-
"codecov": "^3.7.0",
144+
"codecov": "^3.8.1",
145145
"codelyzer": "^5.0.1",
146-
"conventional-changelog": "^3.1.23",
147-
"copyfiles": "^2.3.0",
148-
"core-js": "^2.6.11",
149-
"cross-env": "^7.0.2",
146+
"conventional-changelog": "^3.1.24",
147+
"copyfiles": "^2.4.1",
148+
"core-js": "^2.6.12",
149+
"cross-env": "^7.0.3",
150150
"custom-event-polyfill": "^1.0.7",
151-
"del": "^5.1.0",
151+
"del": "^6.0.0",
152152
"del-cli": "^3.0.1",
153153
"gulp": "^4.0.2",
154154
"gulp-bump": "^3.2.0",
@@ -171,9 +171,9 @@
171171
"ts-node": "~3.3.0",
172172
"tsickle": "^0.37.0",
173173
"tslib": "^2.0.1",
174-
"tslint": "^5.12.0",
174+
"tslint": "^5.20.1",
175175
"typescript": "3.5.3",
176-
"uglify-js": "^3.10.2",
176+
"uglify-js": "^3.12.1",
177177
"vinyl-paths": "^2.1.0",
178178
"yargs": "^15.4.1",
179179
"zone.js": "~0.9.1"

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export class HeaderMenuExtension implements Extension {
331331
case 'freeze-columns':
332332
const visibleColumns = [...this.sharedService.visibleColumns];
333333
const columnPosition = visibleColumns.findIndex((col) => col.id === args.column.id);
334-
this.sharedService.grid.setOptions({ frozenColumn: columnPosition } as GridOption);
334+
this.sharedService.grid.setOptions({ frozenColumn: columnPosition, enableMouseWheelScrollHandler: true } as GridOption);
335335

336336
// to freeze columns, we need to take only the visible columns and we also need to use setColumns() when some of them are hidden
337337
// 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

test/cypress/cypress.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"baseUrl": "http://localhost:4300",
33
"baseExampleUrl": "http://localhost:4300/#",
4+
"runMode": 2,
45
"video": false,
56
"viewportWidth": 1200,
67
"viewportHeight": 950,
@@ -11,4 +12,4 @@
1112
"screenshotsFolder": "screenshots",
1213
"supportFile": "support/index.js",
1314
"videosFolder": "videos"
14-
}
15+
}

test/cypress/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"author": "Ghislain B.",
1111
"license": "MIT",
1212
"devDependencies": {
13-
"cypress": "^5.6.0",
13+
"cypress": "^6.0.1",
1414
"mocha": "^8.2.0",
1515
"mochawesome": "^6.1.1"
1616
}

0 commit comments

Comments
 (0)