Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Add a feature to fit multiple column's width to their content #731

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions packages/datagrid/src/basicmousehandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,32 @@ export class BasicMouseHandler implements DataGrid.IMouseHandler {
return;
}
}

grid.resizeColumn(colRegion, colIndex, null);
const cs = grid.selectionModel?.currentSelection();
const cv = grid.currentViewport;
const rowCount = grid.selectionModel?.dataModel.rowCount('body') ?? 0;
if (
colRegion == 'body' &&
cs != null &&
cv != null &&
cs.r1 == 0 &&
cs.r2 == rowCount - 1
) {
// One or more columns are selected
let c1 = Math.max(Math.min(cs.c1, cs.c2), cv.firstColumn);
let c2 = Math.min(Math.max(cs.c1, cs.c2), cv.lastColumn);
if (c1 <= colIndex && colIndex <= c2) {
// When we double-click one of the selected column headers, resize all visible selected columns.
for (let ci = c1; ci <= c2; ci++) {
grid.resizeColumn(colRegion, ci, null);
}
} else {
// When we double-click the column header outside the selection, resize only the clicked column.
grid.resizeColumn(colRegion, colIndex, null);
}
} else {
// When no columns are selected, resize only the clicked column.
grid.resizeColumn(colRegion, colIndex, null);
}
}
}

Expand Down
Loading