fix: ResizeColumnOnAllRows with Virtualize calculates incorrect height for smaller ItemSize in FluentDataGrid
🐛 Bug Report
Using ResizeColumnOnAllRows with Virtualize calculates resize handle height incorrectly for smaller ItemSize resulting in blank area at the bottom of the grid.
💻 Repro or Code Sample
Using the code from a sample for datagrid virtualization with a change to ItemSize and enabled resizing:
<div style="height: 400px; max-width: 800px; overflow-y: scroll;">
<FluentDataGrid @ref="grid" Items=@items
Virtualize="true"
DisplayMode="DataGridDisplayMode.Table"
Style="width: 100%;"
ResizableColumns
ResizeColumnOnAllRows
ItemSize="40">
<ChildContent>
<PropertyColumn Width="25%" Property="@(c => c.Item1)" Sortable="true" />
<PropertyColumn Width="25%" Property="@(c => c.Item2)" />
<PropertyColumn Width="25%" Property="@(c => c.Item3)" Align="Align.Center" />
<PropertyColumn Width="25%" Property="@(c => c.Item4)" Align="Align.End" />
</ChildContent>
<EmptyContent>
<FluentIcon Value="@(new Icons.Filled.Size24.Crown())" Color="@Color.Accent" /> Nothing to see here. Carry on!
</EmptyContent>
<LoadingContent>
<FluentStack Orientation="Orientation.Vertical" HorizontalAlignment="HorizontalAlignment.Center">
Loading...<br />
<FluentProgress Width="240px" />
</FluentStack>
</LoadingContent>
</FluentDataGrid>
</div>
<br />
<FluentSwitch @ref="_clearToggle"
@bind-Value="@_clearItems"
@bind-Value:after="ToggleItems"
UncheckedMessage="Clear all results"
CheckedMessage="Restore all results">
</FluentSwitch>
<FluentButton OnClick="SimulateDataLoading">Simulate data loading</FluentButton>
@code {
FluentDataGrid<SampleGridData>? grid;
FluentSwitch? _clearToggle;
bool _clearItems = false;
public record SampleGridData(string Item1, string Item2, string Item3, string Item4);
IQueryable<SampleGridData>? items = Enumerable.Empty<SampleGridData>().AsQueryable();
private IQueryable<SampleGridData> GenerateSampleGridData(int size)
{
SampleGridData[] data = new SampleGridData[size];
for (int i = 0; i < size; i++)
{
data[i] = new SampleGridData($"value {i}-1", $"value {i}-2", $"value {i}-3", $"value {i}-4");
}
return data.AsQueryable();
}
protected override void OnInitialized()
{
items = GenerateSampleGridData(5000);
}
private void ToggleItems()
{
if (_clearItems)
{
items = null;
}
else
{
items = GenerateSampleGridData(5000);
}
}
private async Task SimulateDataLoading()
{
_clearItems = false;
items = null;
grid?.SetLoadingState(true);
await Task.Delay(1500);
items = GenerateSampleGridData(5000);
grid?.SetLoadingState(false);
}
}
🤔 Expected Behavior
Resize handle should use correct ItemSize and match the height of virtualized grid.
😯 Current Behavior
Setting ItemSize lower than 47px causes handle to be heigher than the data rows, because the row and header heights do not match.
💁 Possible Solution
The issue seems to be present mostly because the header may be bigger than the rows and the code initializing resize handle assumes header to be the same size.
Passing ItemSize to the initialization JS function directly or parsing it from the header style height (which should be equal to ItemSize) could probably solve the issue.
🔦 Context
Since resize on all rows is enabled by default, I ran into this issue when enabling resize.
🌍 Your Environment
- Windows 11
- Microsoft Edge
- tested on latest release (v4.13.2) and on
devbranch