Skip to content

Commit c58ccec

Browse files
authored
fix: DH-20415: AG Grid headers should match column names (#1261)
- Previously we were omitting the `headerName` property of the column definition. When omitted, AG Grid automatically reformats the header name and adds spaces if it is a PascalCase header name - Explicitly define `headerName` in the ColumnDefinition to match the actual name of the column - Added unit tests, updated e2e tests
1 parent 3645e2a commit c58ccec

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed

plugins/ag-grid/src/js/src/utils/AgGridTableUtils.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ describe('getColumnDefs', () => {
216216
expect(columnDefs).toHaveLength(2);
217217
expect(columnDefs[0].field).toBe('col1');
218218
expect(columnDefs[1].field).toBe('col2');
219+
expect(columnDefs[0].headerName).toBe('col1');
220+
expect(columnDefs[1].headerName).toBe('col2');
219221
});
220222
});
221223

@@ -236,8 +238,10 @@ describe('getColumnDefs', () => {
236238
const columnDefs = getColumnDefs(treeTable);
237239
expect(columnDefs).toHaveLength(2);
238240
expect(columnDefs[0].field).toBe('col1');
241+
expect(columnDefs[0].headerName).toBe('col1');
239242
expect(columnDefs[0].rowGroup).toBe(true);
240243
expect(columnDefs[1].field).toBe('col2');
244+
expect(columnDefs[1].headerName).toBe('col2');
241245
});
242246
});
243247

@@ -263,4 +267,37 @@ describe('getColumnDefs', () => {
263267
expect(columnDefs[2].field).toBe('value1');
264268
});
265269
});
270+
271+
describe('sets headerName explicitly', () => {
272+
// AG Grid by default converts camelCase to 'Camel Case' for header names.
273+
// We want to ensure that column names are used exactly as-is.
274+
it('for table columns', () => {
275+
const table = createMockTable({
276+
columns: [
277+
createMockColumn({ name: 'col1' }),
278+
createMockColumn({ name: 'FooBar' }),
279+
createMockColumn({ name: 'Foo_Bar' }),
280+
],
281+
});
282+
const columnDefs = getColumnDefs(table);
283+
expect(columnDefs[0].headerName).toBe('col1');
284+
expect(columnDefs[1].headerName).toBe('FooBar');
285+
expect(columnDefs[2].headerName).toBe('Foo_Bar');
286+
});
287+
288+
it('for tree table columns', () => {
289+
const treeTable = createMockTreeTable({
290+
columns: [
291+
createMockColumn({ name: 'col1' }),
292+
createMockColumn({ name: 'FooBar' }),
293+
createMockColumn({ name: 'Foo_Bar' }),
294+
],
295+
groupedColumns: [createMockColumn({ name: 'col1' })],
296+
});
297+
const columnDefs = getColumnDefs(treeTable);
298+
expect(columnDefs[0].headerName).toBe('col1');
299+
expect(columnDefs[1].headerName).toBe('FooBar');
300+
expect(columnDefs[2].headerName).toBe('Foo_Bar');
301+
});
302+
});
266303
});

plugins/ag-grid/src/js/src/utils/AgGridTableUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ export function getColumnDefs(table: AgGridTableType): ColDef[] {
152152
const templateColDef: Partial<ColDef> = groupedColSet.has(c.name)
153153
? {
154154
field: c.name,
155+
headerName: c.name,
155156
rowGroup: true,
156157
}
157158
: {
158159
field: c.name,
160+
headerName: c.name,
159161
enableRowGroup: isRowGroupable(c.type),
160162
enableValue: true,
161163
};

tests/ag_grid.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ test('AgGrid with RollupTable loads', async ({ page }) => {
1212
await openPanel(page, 'ag_rollup');
1313
await expect(page.locator('.ag-root')).toHaveScreenshot();
1414
});
15+
16+
test('Column headers match column names match exactly', async ({ page }) => {
17+
await gotoPage(page, '');
18+
await openPanel(page, 'ag_foo_bar');
19+
await expect(page.locator('.ag-header-cell-text')).toHaveText([
20+
'Foo_Bar',
21+
'FooBar',
22+
]);
23+
});
-9 Bytes
Loading
-122 Bytes
Loading
-15 Bytes
Loading

tests/app.d/ag_grid.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,16 @@
1919

2020
rollup = source.rollup(aggs=agg_list, by=by_list)
2121
ag_rollup = AgGrid(rollup)
22+
23+
from deephaven import new_table
24+
from deephaven.column import string_col
25+
from deephaven.ag_grid import AgGrid
26+
27+
foo_bar_table = new_table(
28+
[
29+
string_col("Foo_Bar", ["Foo"]),
30+
string_col("FooBar", ["Bar"]),
31+
]
32+
)
33+
34+
ag_foo_bar = AgGrid(foo_bar_table)

0 commit comments

Comments
 (0)