Maintain column widths when deleting columns (#67707)

This commit is contained in:
Victor Marin 2023-05-03 17:48:30 +03:00 committed by GitHub
parent 2ecc1802e7
commit cd8b6be41d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -220,9 +220,14 @@ export const datagridReducer = (state: DatagridState, action: DatagridAction): D
columns = [
...updateColumnsPayload.frame.fields.map((field: Field, index: number) => {
const displayName = getFieldDisplayName(field, updateColumnsPayload.frame);
// find column by field name and update width in new set. We cannot use index because
// if a column gets deleted we don't know the correct index anymore
const width = state.columns.find((column) => column.title === displayName)?.width;
return {
title: displayName,
width: state.columns[index]?.width ?? getCellWidth(field),
width: width ?? getCellWidth(field),
icon: typeToIconMap.get(field.type),
hasMenu: isDatagridEnabled(),
trailingRowOptions: { targetColumn: --index },