Skip to content

Commit

Permalink
[DataGrid] Fix resizing to initial column widths issue (#2561)
Browse files Browse the repository at this point in the history
* Use dictionary for initialColumnsWidths

* Add cleanup
  • Loading branch information
vnbaaij authored Aug 21, 2024
1 parent 86b74e2 commit ac17756
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Core/Components/DataGrid/FluentDataGrid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ColumnsCollectedNotifier TGridItem="TGridItem" />

<fluent-data-grid @ref=_gridReference
id="@Id"
no-tabbing=@NoTabbing
generate-header="none"
grid-template-columns=@_internalGridTemplateColumns
Expand Down
1 change: 1 addition & 0 deletions src/Core/Components/DataGrid/FluentDataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public partial class FluentDataGrid<TGridItem> : FluentComponentBase, IHandleEve
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(DataGridRowFocusEventArgs))]
public FluentDataGrid()
{
Id = Identifier.NewId();
_columns = [];
_internalGridContext = new(this);
_currentPageItemsChanged = new(EventCallback.Factory.Create<PaginationState>(this, RefreshDataCoreAsync));
Expand Down
11 changes: 6 additions & 5 deletions src/Core/Components/DataGrid/FluentDataGrid.razor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var initialColumnsWidths = '';
let initialColumnsWidths = {};
var latestGridElement = null;

export function init(gridElement) {
Expand All @@ -7,7 +7,7 @@ export function init(gridElement) {
};

if (gridElement.querySelectorAll('.column-header.resizable').length > 0) {
initialColumnsWidths = gridElement.gridTemplateColumns;
initialColumnsWidths[gridElement.id] = gridElement.gridTemplateColumns ;
enableColumnResizing(gridElement);
}

Expand Down Expand Up @@ -63,6 +63,7 @@ export function init(gridElement) {
document.body.removeEventListener('click', bodyClickHandler);
document.body.removeEventListener('mousedown', bodyClickHandler);
document.body.removeEventListener('keydown', keyDownHandler);
delete initialColumnsWidths[gridElement.id];
}
};
}
Expand Down Expand Up @@ -158,8 +159,8 @@ export function enableColumnResizing(gridElement) {
}

export function resetColumnWidths(gridElement) {
gridElement.gridTemplateColumns = initialColumnsWidths;

gridElement.gridTemplateColumns = initialColumnsWidths[gridElement.id];
}

export function resizeColumnDiscrete(gridElement, column, change) {
Expand Down Expand Up @@ -231,7 +232,7 @@ export function autoFitGridColumns(gridElement, columnCount) {
gridElement.setAttribute("grid-template-columns", gridTemplateColumns);
gridElement.classList.remove("auto-fit");

initialColumnsWidths = gridTemplateColumns;
initialColumnsWidths[gridElement.id] = gridTemplateColumns;
}

export function resizeColumnExact(gridElement, column, width) {
Expand Down

0 comments on commit ac17756

Please sign in to comment.