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

feat(resizer): change onGridBeforeResize to return event, issue #215 #216

Merged
merged 1 commit into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/examples/grid-formatter.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<h2>{{title}}</h2>
<div class="subtitle" [innerHTML]="subTitle"></div>

<button class="btn btn-default btn-sm" (click)="togglePauseResizer()">
Pause auto-resize: <b>{{resizerPaused}}</b>
</button>

<angular-slickgrid gridId="grid2"
[columnDefinitions]="columnDefinitions"
[gridOptions]="gridOptions"
Expand Down
7 changes: 7 additions & 0 deletions src/app/examples/grid-formatter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ export class GridFormatterComponent implements OnInit {
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>This example also has auto-resize enabled, and we also demo how you can pause the resizer if you wish to</li>
</ul>
`;

columnDefinitions: Column[];
gridOptions: GridOption;
dataset: any[];
angularGrid: AngularGridInstance;
resizerPaused = false;

angularGridReady(angularGrid: AngularGridInstance) {
this.angularGrid = angularGrid;
Expand Down Expand Up @@ -115,6 +117,11 @@ export class GridFormatterComponent implements OnInit {
return phone;
}

togglePauseResizer() {
this.resizerPaused = !this.resizerPaused;
this.angularGrid.resizerService.pauseResizer(this.resizerPaused);
}

toggleCompletedProperty(item) {
// toggle property
if (typeof item === 'object') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('Resizer Service', () => {
expect(window.innerHeight).not.toEqual(previousHeight);
expect(serviceCalculateSpy).toReturnWith(dimensionResult);
expect(lastDimensions).toEqual(dimensionResult);
expect(subjectBeforeSpy).toHaveBeenCalledWith(true);
expect(subjectBeforeSpy).toHaveBeenCalledWith(expect.any(Object));
expect(subjectAfterSpy).toHaveBeenCalledWith(dimensionResult);
});

Expand Down Expand Up @@ -187,4 +187,18 @@ describe('Resizer Service', () => {
expect(serviceCalculateSpy).toHaveBeenCalled();
expect(gridAutosizeSpy).toHaveBeenCalled();
});

it('should stop resizing when user called "pauseResizer" with true', () => {
service.bindAutoResizeDataGrid();
Object.defineProperty(window, 'innerHeight', { writable: true, configurable: true, value: 450 });
window.dispatchEvent(new Event('resize'));

service.pauseResizer(true);
const spy = jest.spyOn(service, 'resizeGrid');

Object.defineProperty(window, 'innerHeight', { writable: true, configurable: true, value: 550 });
window.dispatchEvent(new Event('resize'));

expect(spy).not.toHaveBeenCalled();
});
});
16 changes: 12 additions & 4 deletions src/app/modules/angular-slickgrid/services/resizer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export class ResizerService {
private _grid: any;
private _lastDimensions: GridDimension;
private _timer: any;
private _resizePaused = false;
onGridAfterResize = new Subject<GridDimension>();
onGridBeforeResize = new Subject<boolean>();
onGridBeforeResize = new Subject<Event>();

/** Getter for the Grid Options pulled through the Grid Object */
private get _gridOptions(): GridOption {
Expand Down Expand Up @@ -59,9 +60,11 @@ export class ResizerService {

// -- 2nd attach a trigger on the Window DOM element, so that it happens also when resizing after first load
// -- attach auto-resize to Window object only if it exist
$(window).on(`resize.grid.${this._gridUid}`, () => {
this.onGridBeforeResize.next(true);
this.resizeGrid(0, newSizes);
$(window).on(`resize.grid.${this._gridUid}`, (event: Event) => {
this.onGridBeforeResize.next(event);
if (!this._resizePaused) {
this.resizeGrid(0, newSizes);
}
});
}

Expand Down Expand Up @@ -164,6 +167,11 @@ export class ResizerService {
return this._lastDimensions;
}

/** Provide the possibility to pause the resizer for some time, until user decides to re-enabled it later if he wish to. */
pauseResizer(isResizePaused: boolean) {
this._resizePaused = isResizePaused;
}

/** Resize the datagrid to fit the browser height & width */
resizeGrid(delay = 10, newSizes?: GridDimension): Promise<GridDimension> {
if (!this._grid || !this._gridOptions) {
Expand Down