Skip to content
Prev Previous commit
Next Next commit
Add ResizeColumnOnAllRows parameter to control column resize behavior
Co-authored-by: vnbaaij <[email protected]>
  • Loading branch information
Copilot and vnbaaij committed Jun 11, 2025
commit 9edef9e108bf13f8dfaaf41c2fd4c48adc7cb604
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<p>To test set ResizeType on the DataGrid to either DataGridResizeType.Discrete or DataGridResizeType.Exact</p>
<p>Remove the parameter completely to get the original behavior</p>
<p>Use ResizeColumnOnAllRows="false" to limit column resizing to header cells only (default is true for all rows)</p>

<div style="height: 380px; overflow-x:auto; display:flex;">
<FluentDataGrid @ref="grid"
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.116",
"version": "9.0.204",
"allowPrerelease": true,
"rollForward": "latestPatch"
}
Expand Down
10 changes: 9 additions & 1 deletion src/Core/Components/DataGrid/FluentDataGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ public partial class FluentDataGrid<TGridItem> : FluentComponentBase, IHandleEve
[Parameter]
public bool ResizableColumns { get; set; }

/// <summary>
/// Gets or sets a value indicating whether column resize handles should extend the full height of the grid.
/// When true, columns can be resized by dragging from any row. When false, columns can only be resized
/// by dragging from the column header. Default is true.
/// </summary>
[Parameter]
public bool ResizeColumnOnAllRows { get; set; } = true;

/// <summary>
/// To comply with WCAG 2.2, a one-click option should be offered to change column widths. We provide such an option through the
/// ColumnOptions UI. This parameter allows you to enable or disable this resize UI.Enable it by setting the type of resize to perform
Expand Down Expand Up @@ -551,7 +559,7 @@ private void FinishCollectingColumns()

if (ResizableColumns)
{
_ = Module?.InvokeVoidAsync("enableColumnResizing", _gridReference).AsTask();
_ = Module?.InvokeVoidAsync("enableColumnResizing", _gridReference, ResizeColumnOnAllRows).AsTask();
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/Core/Components/DataGrid/FluentDataGrid.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function checkColumnPopupPosition(gridElement, selector) {
}
}

export function enableColumnResizing(gridElement) {
export function enableColumnResizing(gridElement, resizeColumnOnAllRows = true) {
const columns = [];
const headers = gridElement.querySelectorAll('.column-header.resizable');

Expand All @@ -184,13 +184,21 @@ export function enableColumnResizing(gridElement) {
}
}

// Determine the height based on the resizeColumnOnAllRows parameter
let resizeHandleHeight = tableHeight;
if (!resizeColumnOnAllRows) {
// Only use the header height when resizeColumnOnAllRows is false
const headerRow = gridElement.querySelector('thead tr th');
resizeHandleHeight = headerRow ? headerRow.offsetHeight : 40; // fallback to 40px if header not found
}

headers.forEach((header) => {
columns.push({
header,
size: `${header.clientWidth}px`,
});

const div = createDiv(tableHeight, isRTL);
const div = createDiv(resizeHandleHeight, isRTL);
header.appendChild(div);
setListeners(div, isRTL);
});
Expand Down
34 changes: 34 additions & 0 deletions tests/Core/DataGrid/FluentDataGridTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,40 @@
cut.Verify();
}

[Fact]
public void FluentDataGrid_ResizeColumnOnAllRows_Default()
{
// Arrange && Act
var cut = Render<FluentDataGrid<Customer>>(
@<FluentDataGrid Items="@GetCustomers().AsQueryable()" ResizableColumns="true">
<ChildContent>
<PropertyColumn Property="@(x => x.Name)" />
</ChildContent>
</FluentDataGrid>);

// Assert
var component = cut.Instance;
Assert.True(component.ResizeColumnOnAllRows); // Default should be true
}

[Fact]
public void FluentDataGrid_ResizeColumnOnAllRows_False()
{
// Arrange && Act
var cut = Render<FluentDataGrid<Customer>>(
@<FluentDataGrid Items="@GetCustomers().AsQueryable()"
ResizableColumns="true"
ResizeColumnOnAllRows="false">
<ChildContent>
<PropertyColumn Property="@(x => x.Name)" />
</ChildContent>
</FluentDataGrid>);

// Assert
var component = cut.Instance;
Assert.False(component.ResizeColumnOnAllRows);
}

[Fact]
public void FluentDataGrid_With_Empty_Items_Stays_Loading_Until_Changed()
{
Expand Down