Skip to content

Commit

Permalink
fix(services): fix couple of issues found with custom grid views
Browse files Browse the repository at this point in the history
- avoid showing scrolling on frozen grid
- avoid triggering event when calling `changeColumnsArrangement` and it's not on first page load
  • Loading branch information
ghiscoding committed May 18, 2021
1 parent b54437c commit db06736
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/common/src/services/__tests__/grid.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ describe('Grid Service', () => {

service.setPinning(mockPinning);

expect(setOptionsSpy).toHaveBeenCalledWith(mockPinning, false, true);
expect(setOptionsSpy).toHaveBeenCalledWith({ ...mockPinning, alwaysShowVerticalScroll: false }, false, true);
expect(gridOptionSetterSpy).toHaveBeenCalledWith(mockPinning);
expect(autosizeColumnsSpy).toHaveBeenCalled();
});
Expand All @@ -1105,7 +1105,7 @@ describe('Grid Service', () => {

service.setPinning(mockPinning, false);

expect(setOptionsSpy).toHaveBeenCalledWith(mockPinning, false, true);
expect(setOptionsSpy).toHaveBeenCalledWith({ ...mockPinning, alwaysShowVerticalScroll: false }, false, true);
expect(gridOptionSetterSpy).toHaveBeenCalledWith(mockPinning);
expect(autosizeColumnsSpy).not.toHaveBeenCalled();
});
Expand Down
17 changes: 16 additions & 1 deletion packages/common/src/services/__tests__/gridState.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,22 @@ describe('GridStateService', () => {
expect(pubSubSpy).toHaveBeenCalledWith('onFullResizeByContentRequested', { caller: 'GridStateService' });
});

it('should call the method and expect slickgrid "setColumns" and a pubsub event "onFullResizeByContentRequested" to be called with newest columns when "triggerAutoSizeColumns" is false and "enableAutoResizeColumnsByCellContent" is true', () => {
it('should call the method and expect slickgrid "setColumns" but WITHOUT triggering pubsub event "onFullResizeByContentRequested" because it requires "enableAutoResizeColumnsByCellContent: true" AND "autosizeColumnsByCellContentOnFirstLoad: false" because this method is never called on first page load', () => {
gridOptionMock.enableAutoResizeColumnsByCellContent = true;
gridOptionMock.autosizeColumnsByCellContentOnFirstLoad = true;
jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(allColumnsMock);
const setColsSpy = jest.spyOn(gridStub, 'setColumns');
const autoSizeSpy = jest.spyOn(gridStub, 'autosizeColumns');
const pubSubSpy = jest.spyOn(mockPubSub, 'publish');

service.changeColumnsArrangement(presetColumnsMock, false);

expect(setColsSpy).toHaveBeenCalledWith([rowCheckboxColumnMock, ...columnsWithoutCheckboxMock]);
expect(autoSizeSpy).not.toHaveBeenCalled();
expect(pubSubSpy).not.toHaveBeenCalledWith('onFullResizeByContentRequested', { caller: 'GridStateService' });
});

it('should call the method and expect slickgrid "setColumns" and a pubsub event "onFullResizeByContentRequested" to be called with newest columns when "triggerAutoSizeColumns" is false and 3rd is set to true', () => {
jest.spyOn(SharedService.prototype, 'allColumns', 'get').mockReturnValue(allColumnsMock);
const setColsSpy = jest.spyOn(gridStub, 'setColumns');
const autoSizeSpy = jest.spyOn(gridStub, 'autosizeColumns');
Expand Down
8 changes: 6 additions & 2 deletions packages/common/src/services/grid.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ export class GridService {
* @param {Boolean} suppressColumnSet - do we want to supress the columns set, via "setColumns()" method? (defaults to false)
*/
setPinning(pinningOptions: CurrentPinning, shouldAutosizeColumns = true, suppressRender = false, suppressColumnSet = true) {
this.sharedService.slickGrid.setOptions(pinningOptions, suppressRender, suppressColumnSet);
this.sharedService.gridOptions = { ...this.sharedService.gridOptions, ...pinningOptions };
const options = pinningOptions as GridOption;
if (typeof pinningOptions?.frozenColumn === 'number' && pinningOptions.frozenColumn >= 0) {
options.alwaysShowVerticalScroll = false; // make sure to never show the verticall scroll when the grid has pinning (frozen column)
}
this.sharedService.slickGrid.setOptions(options, suppressRender, suppressColumnSet);
this.sharedService.gridOptions = { ...this.sharedService.gridOptions, ...options };

if (shouldAutosizeColumns) {
this.sharedService.slickGrid.autosizeColumns();
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/services/gridState.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class GridStateService {
// resize the columns to fit the grid canvas
if (triggerAutoSizeColumns) {
this._grid.autosizeColumns();
} else if (triggerColumnsFullResizeByContent || this._gridOptions.enableAutoResizeColumnsByCellContent) {
} else if (triggerColumnsFullResizeByContent || (this._gridOptions.enableAutoResizeColumnsByCellContent && !this._gridOptions.autosizeColumnsByCellContentOnFirstLoad)) {
this.pubSubService.publish('onFullResizeByContentRequested', { caller: 'GridStateService' });
}
}
Expand Down
Binary file not shown.

0 comments on commit db06736

Please sign in to comment.