Skip to content

Commit

Permalink
fix: cap width of columns with long names (#1574)
Browse files Browse the repository at this point in the history
Closes #1276 
- adds a max column width in GridMetricCalculator
- value is obtained from GridTheme
  • Loading branch information
ethanalvizo authored Oct 18, 2023
1 parent 94ab25c commit 876a6ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/grid/src/GridMetricCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ export class GridMetricCalculator {
treePaddingX: number = this.calculateTreePaddingX(state)
): number {
const { theme } = state;
const { autoSizeColumns, minColumnWidth } = theme;
const { autoSizeColumns, minColumnWidth, maxColumnWidth } = theme;
if (!autoSizeColumns) {
const { columnWidth } = theme;
return columnWidth;
Expand All @@ -1667,6 +1667,7 @@ export class GridMetricCalculator {
const cachedValue = this.calculatedColumnWidths.get(modelColumn);
let columnWidth = Math.ceil(Math.max(headerWidth, dataWidth));
columnWidth = Math.max(minColumnWidth, columnWidth);
columnWidth = Math.min(maxColumnWidth, columnWidth);
if (cachedValue != null && cachedValue > columnWidth) {
columnWidth = cachedValue;
} else {
Expand Down
2 changes: 2 additions & 0 deletions packages/grid/src/GridTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export type GridTheme = {
columnWidth: number;
minRowHeight: number;
minColumnWidth: number;
maxColumnWidth: number;

// Default row/column header/footers width/height
columnHeaderHeight: number;
Expand Down Expand Up @@ -206,6 +207,7 @@ const defaultTheme: GridTheme = Object.freeze({
columnWidth: 100,
minRowHeight: 20,
minColumnWidth: 55,
maxColumnWidth: 600,
columnHeaderHeight: 20,
rowHeaderWidth: 30,
rowFooterWidth: 0,
Expand Down

0 comments on commit 876a6ac

Please sign in to comment.