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

Commit 0ef4f35

Browse files
authored
Merge pull request #637 from ghiscoding/bugfix/header-colums-group-hide-column
fix(core): header columns grouping misbehave after hiding column
2 parents 9ce8326 + 9a1731e commit 0ef4f35

File tree

9 files changed

+48
-23
lines changed

9 files changed

+48
-23
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,6 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
12471247
describe('pagination events', () => {
12481248
beforeEach(() => {
12491249
jest.clearAllMocks();
1250-
component.destroy();
12511250
});
12521251

12531252
it('should merge paginationOptions when some already exist', () => {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
344344
this.datasetHierarchical = null;
345345
this._columnDefinitions = [];
346346
this._angularGridInstances = null;
347+
this.grid = null;
348+
this.gridOptions = null;
349+
this.dataView = null;
347350
}
348351

349352
emptyGridContainerElm() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class HeaderMenuExtension implements Extension {
224224
const visibleColumns = arrayRemoveItemByIndex(currentColumns, columnIndex);
225225
this.sharedService.visibleColumns = visibleColumns;
226226
this.sharedService.grid.setColumns(visibleColumns);
227-
this.sharedService.onColumnsChanged.next(visibleColumns);
227+
this.sharedService.onHeaderMenuHideColumns.next(visibleColumns);
228228
}
229229
}
230230

src/app/modules/angular-slickgrid/services/__tests__/gridState.service.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ describe('GridStateService', () => {
921921
const getCurGridStateSpy = jest.spyOn(service, 'getCurrentGridState').mockReturnValue(gridStateMock);
922922
const getAssocCurColSpy = jest.spyOn(service, 'getAssociatedCurrentColumns').mockReturnValue(currentColumnsMock);
923923

924-
sharedService.onColumnsChanged.next(columnsMock);
924+
sharedService.onHeaderMenuHideColumns.next(columnsMock);
925925

926926
expect(getCurGridStateSpy).toHaveBeenCalled();
927927
expect(getAssocCurColSpy).toHaveBeenCalled();

src/app/modules/angular-slickgrid/services/__tests__/groupingAndColspan.service.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ describe('GroupingAndColspanService', () => {
8484
let service: GroupingAndColspanService;
8585
let translate: TranslateService;
8686
let slickgridEventHandler: SlickEventHandler;
87+
const sharedService = new SharedService();
8788

8889
beforeEach(() => {
8990
const div = document.createElement('div');
9091
div.innerHTML = template;
9192
document.body.appendChild(div);
9293

93-
// service = new GroupingAndColspanService(resizerServiceStub);
9494

9595
TestBed.configureTestingModule({
9696
providers: [
@@ -99,6 +99,7 @@ describe('GroupingAndColspanService', () => {
9999
{ provide: ExtensionUtility, useValue: mockExtensionUtility },
100100
{ provide: ExtensionService, useValue: extensionServiceStub },
101101
{ provide: ResizerService, useValue: resizerServiceStub },
102+
{ provide: SharedService, useValue: sharedService },
102103
],
103104
imports: [TranslateModule.forRoot()]
104105
});
@@ -356,5 +357,19 @@ describe('GroupingAndColspanService', () => {
356357
expect(divHeaderColumns.length).toBeGreaterThan(2);
357358
expect(divHeaderColumns[0].outerHTML).toEqual(`<div style="width: 2815px; left: -1000px;" class="slick-header-columns">All your colums div here</div>`);
358359
});
360+
361+
it('should call the "renderPreHeaderRowGroupingTitles" when "onHeaderMenuHideColumns" is triggered', () => {
362+
const columnsMock = [{ id: 'field1', field: 'field1', width: 100, cssClass: 'red' }] as Column[];
363+
const divHeaderColumns = document.getElementsByClassName('slick-header-columns');
364+
jest.spyOn(gridStub, 'getColumns').mockReturnValue(mockColumns);
365+
const spy = jest.spyOn(service, 'renderPreHeaderRowGroupingTitles');
366+
367+
service.init(gridStub, dataViewStub);
368+
sharedService.onHeaderMenuHideColumns.next(columnsMock);
369+
jest.runAllTimers(); // fast-forward timer
370+
371+
expect(spy).toHaveBeenCalledTimes(2); // 1x for init, 1x for event
372+
expect(divHeaderColumns.length).toBeGreaterThan(2);
373+
});
359374
});
360375
});

src/app/modules/angular-slickgrid/services/gridState.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ export class GridStateService {
359359

360360
// subscribe to HeaderMenu (hide column)
361361
this._subscriptions.push(
362-
this.sharedService.onColumnsChanged.subscribe((visibleColumns: Column[]) => {
362+
this.sharedService.onHeaderMenuHideColumns.subscribe((visibleColumns: Column[]) => {
363363
const currentColumns: CurrentColumn[] = this.getAssociatedCurrentColumns(visibleColumns);
364364
this.onGridStateChanged.next({ change: { newValues: currentColumns, type: GridStateType.columns }, gridState: this.getCurrentGridState() });
365365
})

src/app/modules/angular-slickgrid/services/groupingAndColspan.service.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ExtensionUtility } from '../extensions/extensionUtility';
66
import { ExtensionService } from './extension.service';
77
import { ResizerService } from './resizer.service';
88
import { unsubscribeAllObservables } from './utilities';
9+
import { SharedService } from './shared.service';
910

1011
// using external non-typed js libraries
1112
declare let $: any;
@@ -19,7 +20,7 @@ export class GroupingAndColspanService {
1920
private _grid: any;
2021
private subscriptions: Subscription[] = [];
2122

22-
constructor(private extensionUtility: ExtensionUtility, private extensionService: ExtensionService, private resizerService: ResizerService) {
23+
constructor(private extensionUtility: ExtensionUtility, private extensionService: ExtensionService, private resizerService: ResizerService, private sharedService: SharedService) {
2324
this._eventHandler = new Slick.EventHandler();
2425
}
2526

@@ -51,13 +52,14 @@ export class GroupingAndColspanService {
5152
this._eventHandler.subscribe(grid.onColumnsReordered, () => this.renderPreHeaderRowGroupingTitles());
5253
this._eventHandler.subscribe(dataView.onRowCountChanged, () => this.renderPreHeaderRowGroupingTitles());
5354
this.subscriptions.push(
54-
this.resizerService.onGridAfterResize.subscribe(() => this.renderPreHeaderRowGroupingTitles())
55+
this.resizerService.onGridAfterResize.subscribe(() => this.renderPreHeaderRowGroupingTitles()),
56+
this.sharedService.onHeaderMenuHideColumns.subscribe(() => this.delayRenderPreHeaderRowGroupingTitles(0))
5557
);
5658

5759
this._eventHandler.subscribe(grid.onSetOptions, (_e, args) => {
5860
// when user changes frozen columns dynamically (e.g. from header menu), we need to re-render the pre-header of the grouping titles
5961
if (args && args.optionsBefore && args.optionsAfter && args.optionsBefore.frozenColumn !== args.optionsAfter.frozenColumn) {
60-
setTimeout(() => this.renderPreHeaderRowGroupingTitles(), 0);
62+
this.delayRenderPreHeaderRowGroupingTitles(0);
6163
}
6264
});
6365

@@ -75,7 +77,7 @@ export class GroupingAndColspanService {
7577

7678
// also not sure why at this point, but it seems that I need to call the 1st create in a delayed execution
7779
// probably some kind of timing issues and delaying it until the grid is fully ready fixes this problem
78-
setTimeout(() => this.renderPreHeaderRowGroupingTitles(), 50);
80+
this.delayRenderPreHeaderRowGroupingTitles(50);
7981
}
8082
}
8183
}
@@ -88,6 +90,11 @@ export class GroupingAndColspanService {
8890
this.subscriptions = unsubscribeAllObservables(this.subscriptions);
8991
}
9092

93+
/** call "renderPreHeaderRowGroupingTitles()" with a setTimeout delay */
94+
delayRenderPreHeaderRowGroupingTitles(delay = 0) {
95+
setTimeout(() => this.renderPreHeaderRowGroupingTitles(), delay);
96+
}
97+
9198
/** Create or Render the Pre-Header Row Grouping Titles */
9299
renderPreHeaderRowGroupingTitles() {
93100
if (this._gridOptions && this._gridOptions.frozenColumn !== undefined && this._gridOptions.frozenColumn >= 0) {

src/app/modules/angular-slickgrid/services/shared.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class SharedService {
1212
private _hideHeaderRowAfterPageLoad = false;
1313
private _visibleColumns: Column[];
1414
private _hierarchicalDataset: any[] | null;
15-
onColumnsChanged = new Subject<Column[]>();
15+
onHeaderMenuHideColumns = new Subject<Column[]>();
1616

1717
// --
1818
// public

test/cypress/integration/example12.spec.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,6 @@ describe('Example 12: Localization (i18n)', () => {
3636
.each(($child, index) => expect($child.text()).to.eq(fullEnglishTitles[index]));
3737
});
3838

39-
it('should have some metrics shown in the grid footer', () => {
40-
cy.get('#slickGridContainer-grid12')
41-
.find('.slick-custom-footer')
42-
.find('.right-footer')
43-
.should($span => {
44-
const text = removeExtraSpaces($span.text()); // remove all white spaces
45-
const now = new Date();
46-
const dateFormatted = moment(now).format('YYYY-MM-DD, hh:mm a');
47-
expect(text).to.eq(`Last Update ${dateFormatted} | 1500 of 1500 items`);
48-
});
49-
});
50-
5139
it('should filter certain tasks with the word "ask 1" and expect filter to use contain/include text', () => {
5240
const tasks = ['Task 1', 'Task 10', 'Task 11', 'Task 12'];
5341

@@ -280,6 +268,19 @@ describe('Example 12: Localization (i18n)', () => {
280268
.contains('Task 4');
281269
});
282270

271+
it('should have some metrics shown in the grid footer', () => {
272+
const now = new Date();
273+
const dateFormatted = moment(now).format('YYYY-MM-DD, hh:mm a');
274+
275+
cy.get('#slickGridContainer-grid12')
276+
.find('.slick-custom-footer')
277+
.find('.right-footer')
278+
.should($span => {
279+
const text = removeExtraSpaces($span.text()); // remove all white spaces
280+
expect(text).to.eq(`Last Update ${dateFormatted} | 447 of 1500 items`);
281+
});
282+
});
283+
283284
it('should scroll back to the top and expect to see "Task 1497" still selected', () => {
284285
cy.get('#slickGridContainer-grid12').as('grid12');
285286

@@ -290,7 +291,7 @@ describe('Example 12: Localization (i18n)', () => {
290291
cy.get('@grid12')
291292
.find('.slick-viewport-top.slick-viewport-left')
292293
.scrollTo('top')
293-
.wait(10);
294+
.wait(25);
294295

295296
cy.get('@grid12')
296297
.find('.slick-row')

0 commit comments

Comments
 (0)