Skip to content

Commit beda628

Browse files
committed
fix(header): column header grouping should be re-render after a resize
- without a re-render, the column grouping simply goes away completely and nothing is shown in the pre-header after a resize
1 parent f02ac2d commit beda628

File tree

5 files changed

+56
-20
lines changed

5 files changed

+56
-20
lines changed

src/app/examples/grid-colspan.component.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ export class GridColspanComponent implements OnInit {
1414
Row Colspan - (<a href="https://github.com/ghiscoding/Angular-Slickgrid/wiki/Row-Colspan" target="_blank">Wiki docs</a>) /
1515
Header Grouping - (<a href="https://github.com/ghiscoding/Angular-Slickgrid/wiki/Header-Title-Grouping" target="_blank">Wiki docs</a>)
1616
</li>
17-
<li>Note that you can add Sort but remember that it will sort by the data that the row contains, even if the data is visually hidden by colspan it will still sort it</li>
18-
<li>
19-
Header Grouping spanning accross multiple columns is working but has some UI issues on window resize.
20-
If anyone can fix it, probably some CSS issues, please let us know.
21-
</li>
17+
<li>Note that you can add Sort but remember that it will sort by the data which the row contains, even if the data is visually hidden by colspan it will still sort it</li>
2218
</ul>
2319
`;
2420

@@ -51,7 +47,7 @@ export class GridColspanComponent implements OnInit {
5147
enableSorting: true,
5248
createPreHeaderPanel: true,
5349
showPreHeaderPanel: true,
54-
preHeaderPanelHeight: 25,
50+
preHeaderPanelHeight: 28,
5551
explicitInitialization: true,
5652
colspanCallback: this.renderDifferentColspan
5753
};

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

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { Subject } from 'rxjs';
2+
13
import { GroupingAndColspanService } from '../groupingAndColspan.service';
24
import { GridOption, SlickEventHandler, Column } from '../../models';
5+
import { ResizerService, GridDimension } from '../resizer.service';
36

47
declare var Slick: any;
58
const gridId = 'grid1';
@@ -36,6 +39,15 @@ const gridStub = {
3639
setSortColumns: jest.fn(),
3740
};
3841

42+
const resizerServiceStub = {
43+
init: jest.fn(),
44+
dispose: jest.fn(),
45+
bindAutoResizeDataGrid: jest.fn(),
46+
compensateHorizontalScroll: jest.fn(),
47+
resizeGrid: jest.fn(),
48+
onGridAfterResize: new Subject<GridDimension>(),
49+
} as unknown as ResizerService;
50+
3951
jest.useFakeTimers();
4052

4153
// define a <div> container to simulate the grid container
@@ -60,7 +72,7 @@ describe('GroupingAndColspanService', () => {
6072
div.innerHTML = template;
6173
document.body.appendChild(div);
6274

63-
service = new GroupingAndColspanService();
75+
service = new GroupingAndColspanService(resizerServiceStub);
6476
slickgridEventHandler = service.eventHandler;
6577
});
6678

@@ -150,6 +162,18 @@ describe('GroupingAndColspanService', () => {
150162
expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 50);
151163
});
152164

165+
it('should call the "renderPreHeaderRowGroupingTitles" after triggering a grid resize', () => {
166+
const spy = jest.spyOn(service, 'renderPreHeaderRowGroupingTitles');
167+
168+
service.init(gridStub, dataViewStub);
169+
resizerServiceStub.onGridAfterResize.next({ height: 100, width: 100 });
170+
jest.runAllTimers(); // fast-forward timer
171+
172+
expect(spy).toHaveBeenCalledTimes(2);
173+
expect(setTimeout).toHaveBeenCalledTimes(1);
174+
// expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), 75);
175+
});
176+
153177
it('should render the pre-header row grouping title DOM element', () => {
154178
const spy = jest.spyOn(service, 'renderPreHeaderRowGroupingTitles');
155179
const divHeaderColumns = document.getElementsByClassName('slick-header-columns');

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
import { Injectable } from '@angular/core';
12

23
import {
34
Column,
45
GridOption,
56
SlickEventHandler,
67
} from './../models/index';
8+
import { ResizerService } from './resizer.service';
79

810
// using external non-typed js libraries
911
declare let $: any;
1012

1113
// using external non-typed js libraries
1214
declare var Slick: any;
1315

16+
@Injectable()
1417
export class GroupingAndColspanService {
1518
private _eventHandler: SlickEventHandler;
1619
private _grid: any;
1720

18-
constructor() {
21+
constructor(private resizerService: ResizerService) {
1922
this._eventHandler = new Slick.EventHandler();
2023
}
2124

@@ -45,6 +48,7 @@ export class GroupingAndColspanService {
4548
this._eventHandler.subscribe(grid.onSort, () => this.renderPreHeaderRowGroupingTitles());
4649
this._eventHandler.subscribe(grid.onColumnsResized, () => this.renderPreHeaderRowGroupingTitles());
4750
this._eventHandler.subscribe(dataView.onRowCountChanged, () => this.renderPreHeaderRowGroupingTitles());
51+
this.resizerService.onGridAfterResize.subscribe(() => this.renderPreHeaderRowGroupingTitles());
4852

4953
// also not sure why at this point, but it seems that I need to call the 1st create in a delayed execution
5054
// probably some kind of timing issues and delaying it until the grid is fully ready does help

src/app/modules/angular-slickgrid/styles/_variables.scss

+7-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ $row-checkbox-selector-background: inherit !default;
4848
$row-checkbox-selector-border: none !default;
4949

5050
/* Pre-Header - Header Grouping colspan */
51-
$preheader-border-left: none !default;
52-
$preheader-border-right: none !default;
53-
$preheader-border-bottom: none !default;
54-
$preheader-border-top: none !default;
55-
$preheader-font-size: $font-size-base + 2px !default;
51+
$preheader-border-left: none !default;
52+
$preheader-border-left-first-element: none !default;
53+
$preheader-border-right: none !default;
54+
$preheader-border-right-last-element: none !default;
55+
$preheader-border-bottom: none !default;
56+
$preheader-border-top: none !default;
57+
$preheader-font-size: $font-size-base + 3px !default;
5658

5759
/* header */
5860
$header-font-weight: bold !default;

src/app/modules/angular-slickgrid/styles/slick-bootstrap.scss

+17-7
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,6 @@
247247
}
248248
}
249249

250-
.slick-preheader-panel.ui-state-default {
251-
.slick-header-column {
252-
border-left: $preheader-border-left !important;
253-
font-size: $preheader-font-size !important;
254-
}
255-
}
256-
257250
.slick-header-columns {
258251
background: $table-background;
259252
width: calc(100% - #{$header-scroll-width-to-remove});
@@ -352,6 +345,23 @@
352345
}
353346
}
354347

348+
/** Header Grouping **/
349+
.slick-preheader-panel.ui-state-default {
350+
.slick-header-column {
351+
border-left: $preheader-border-left;
352+
border-right: $preheader-border-right;
353+
border-bottom: $preheader-border-bottom;
354+
border-top: $preheader-border-top;
355+
font-size: $preheader-font-size;
356+
}
357+
.slick-header-column:first-child {
358+
border-left: $preheader-border-left-first-element;
359+
}
360+
.slick-header-column:last-child {
361+
border-right: $preheader-border-right-last-element;
362+
}
363+
}
364+
355365
/** Frozen/Pinned styling */
356366

357367
.slick-row .slick-cell.frozen:last-child,

0 commit comments

Comments
 (0)