microsoft / fluentui-blazor

Microsoft Fluent UI Blazor components library. For use with ASP.NET Core Blazor applications
https://www.fluentui-blazor.net
MIT License
3.23k stars 294 forks source link

Cells have an offset when Width is defined for single column #1954

Closed MarvinKlein1508 closed 3 weeks ago

MarvinKlein1508 commented 3 weeks ago

🐛 Bug Report

When using Width to define a columns width in a FluentDataGrid, the other columns will result in an offset when no Width is defined for each column. In my case I want to show a button in the first column with a fixed width and then give the other 95% to all other columns.

grafik

💻 Repro or Code Sample

<FluentDataGrid Items="@people">
    <TemplateColumn Width="5%">
        <FluentButton>Test</FluentButton>
    </TemplateColumn>
    <PropertyColumn Property="@(p => p.PersonId)" Sortable="true" />
    <PropertyColumn Property="@(p => p.Name)" Sortable="true" />
    <PropertyColumn Property="@(p => p.BirthDate)" Format="yyyy-MM-dd" Sortable="true" />
</FluentDataGrid>

@code {
    record Person(int PersonId, string Name, DateOnly BirthDate);

    IQueryable<Person> people = new[]
    {
        new Person(10895, "Jean Martin", new DateOnly(1985, 3, 16)),
        new Person(10944, "António Langa", new DateOnly(1991, 12, 1)),
        new Person(11203, "Julie Smith", new DateOnly(1958, 10, 10)),
        new Person(11205, "Nur Sari", new DateOnly(1922, 4, 27)),
        new Person(11898, "Jose Hernandez", new DateOnly(2011, 5, 3)),
        new Person(12130, "Kenji Sato", new DateOnly(2004, 1, 9)),
    }.AsQueryable();
}
vnbaaij commented 3 weeks ago

This comes from the code using 'auto' in the grid-template-columns in case no Width is specified.

So going with your example the value becomes 5% auto auto auto. As each row has a display of grid, that leads to the effect you are seeing. Some cells will be wider when a name is longer.

I'll change it to use 1fr as the default Width value for the next release. For now you'll just have to specify the widths on all columns.

MarvinKlein1508 commented 3 weeks ago

@vnbaaij thanks for your input! I appreciate your work! :)