Skip to content

Commit 2e5682c

Browse files
committed
fix(common): resolve getHeaderColumn with hidden leading columns
1 parent 839e0a8 commit 2e5682c

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

packages/common/src/core/__tests__/slickGrid.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,23 @@ describe('SlickGrid core file', () => {
21222122
expect(slickRowElms[0].classList.contains('highlight-animate')).toBeFalsy();
21232123
expect(slickRowElms[1].classList.contains('highlight-animate')).toBeFalsy();
21242124
});
2125+
2126+
it('should return the correct header column by id when a hidden column precedes it', () => {
2127+
const columns = [
2128+
{ id: 'a', field: 'a', name: 'A', hidden: true },
2129+
{ id: 'b', field: 'b', name: 'B' },
2130+
{ id: 'c', field: 'c', name: 'C' },
2131+
] as Column[];
2132+
const rows = [{ id: 0, a: 'x', b: 'y', c: 'z' }];
2133+
2134+
grid = new SlickGrid<any, Column>(container, rows, columns, defaultOptions);
2135+
grid.init();
2136+
2137+
const headerElm = grid.getHeaderColumn('b');
2138+
2139+
expect(headerElm).toBeInstanceOf(HTMLDivElement);
2140+
expect(headerElm.dataset.id).toBe('b');
2141+
});
21252142
});
21262143

21272144
describe('flashCell() method', () => {

packages/common/src/core/slickGrid.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,12 +1640,19 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
16401640
*/
16411641
getHeaderColumn(columnIdOrIdx: number | string): HTMLDivElement {
16421642
const idx = typeof columnIdOrIdx === 'number' ? columnIdOrIdx : this.getColumnIndex(columnIdOrIdx);
1643-
// prettier-ignore
1644-
const targetHeader = this.hasFrozenColumns() ? ((idx <= this._options.frozenColumn!) ? this._headerL : this._headerR) : this._headerL;
1645-
// prettier-ignore
1646-
const targetIndex = this.hasFrozenColumns() ? ((idx <= this._options.frozenColumn!) ? idx : idx - this._options.frozenColumn! - 1) : idx;
1643+
const targetHeader = this.hasFrozenColumns() ? (idx <= this._options.frozenColumn! ? this._headerL : this._headerR) : this._headerL;
1644+
const targetIndex = this.hasFrozenColumns() ? (idx <= this._options.frozenColumn! ? idx : idx - this._options.frozenColumn! - 1) : idx;
1645+
const directMatch = targetHeader.children[targetIndex] as HTMLDivElement | undefined;
1646+
const targetColumnId = String(this.columns[idx]?.id ?? columnIdOrIdx);
1647+
const directMatchColumn = Utils.storage.get(directMatch, 'column') as C | undefined;
1648+
if (directMatch && (directMatch.dataset?.id === targetColumnId || String(directMatchColumn?.id) === targetColumnId)) {
1649+
return directMatch;
1650+
}
16471651

1648-
return targetHeader.children[targetIndex] as HTMLDivElement;
1652+
return (
1653+
(Array.from(targetHeader.children).find((child) => (child as HTMLDivElement).dataset?.id === targetColumnId) as HTMLDivElement) ||
1654+
(undefined as any)
1655+
);
16491656
}
16501657

16511658
/** Get the Header Row DOM element */

0 commit comments

Comments
 (0)