Skip to content

Commit 2bcd322

Browse files
author
fergusbissetnhs
committed
fix: Improvements to the GroupableDataGrid
1 parent 19358d0 commit 2bcd322

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

src/components/GroupableDataGrid/GroupableDataGrid.tsx

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
GroupableDataGridProps,
1717
FlattenedNode,
1818
} from "./GroupableDataGrid.types";
19+
1920
import { HierarchyDataManager } from "./utils/HierarchyDataManager";
2021
import { useGroupExpansion } from "./hooks/useGroupExpansion";
2122
import { useTreeNavigation } from "./hooks/useTreeNavigation";
@@ -133,13 +134,34 @@ function renderDataRow<T>(
133134
? String(value)
134135
: "—";
135136

137+
// Wrap content in a div when maxWidth is specified for proper truncation
138+
const wrappedContent = column.maxWidth ? (
139+
<div
140+
style={{
141+
maxWidth: column.maxWidth,
142+
overflow: 'hidden',
143+
textOverflow: 'ellipsis',
144+
whiteSpace: 'nowrap',
145+
}}
146+
title={typeof cellContent === 'string' ? cellContent : undefined}
147+
>
148+
{cellContent}
149+
</div>
150+
) : cellContent;
151+
136152
return (
137153
<td
138154
key={column.key}
139155
className="groupable-datagrid__data-cell"
140156
role="gridcell"
157+
style={{
158+
width: column.width,
159+
minWidth: column.minWidth,
160+
maxWidth: column.maxWidth,
161+
textAlign: column.align,
162+
}}
141163
>
142-
{cellContent}
164+
{wrappedContent}
143165
</td>
144166
);
145167
})}
@@ -796,26 +818,32 @@ export const GroupableDataGrid = <T extends any = any>({
796818
(s) => s.key === column.key
797819
);
798820

799-
return (
800-
<th
801-
key={column.key}
802-
role="columnheader"
803-
aria-sort={
804-
columnSort
805-
? columnSort.direction === "asc"
806-
? "ascending"
807-
: "descending"
808-
: undefined
809-
}
810-
className={classNames("groupable-datagrid__header-cell", {
811-
"groupable-datagrid__header-cell--sortable": isSortable,
812-
"groupable-datagrid__header-cell--sorted": !!columnSort,
813-
})}
814-
onClick={
815-
isSortable ? () => handleSort(column.key) : undefined
816-
}
817-
style={{ cursor: isSortable ? "pointer" : undefined }}
818-
>
821+
return (
822+
<th
823+
key={column.key}
824+
role="columnheader"
825+
aria-sort={
826+
columnSort
827+
? columnSort.direction === "asc"
828+
? "ascending"
829+
: "descending"
830+
: undefined
831+
}
832+
className={classNames("groupable-datagrid__header-cell", {
833+
"groupable-datagrid__header-cell--sortable": isSortable,
834+
"groupable-datagrid__header-cell--sorted": !!columnSort,
835+
})}
836+
onClick={
837+
isSortable ? () => handleSort(column.key) : undefined
838+
}
839+
style={{
840+
cursor: isSortable ? "pointer" : undefined,
841+
width: column.width,
842+
minWidth: column.minWidth,
843+
maxWidth: column.maxWidth,
844+
textAlign: column.align,
845+
}}
846+
>
819847
<div className="groupable-datagrid__header-content">
820848
<span>{column.label}</span>
821849
{isSortable && (

src/components/SortableDataTable/AriaDataGridTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ export interface ColumnDefinition {
8383
width?: string | number;
8484
/** Minimum width for this column when calculating layout (overrides global minColumnWidth) */
8585
minWidth?: string | number;
86+
/** Maximum width for this column. Content will be truncated with ellipsis when exceeded. */
87+
maxWidth?: string | number;
8688
align?: "left" | "center" | "right";
8789
render?: (data: any) => any;
8890
/** Enhanced renderer for table view (overrides render if provided) */

0 commit comments

Comments
 (0)