Skip to content

Commit

Permalink
[DataGrid] Alter rendering to use table elements (#2664)
Browse files Browse the repository at this point in the history
* Replace grid web components with regular table elements

* Adjust styling

* Resize rework

* - Rename example EventHandlers
- Adapt more samples to table rendering
- Undo Tabs example changes
- Remove grid custom events from script etc

* - Redo AutoFit based on table-layout
- Clean up CSS,  commented code/apply code styles
- revert `.col-header` rename (back to `.column-header) to have less breaking changes
- Fix some samples

* - CSS cleanup

* - Remove commented code
- Fix resize reset
- Make size related methods public
- Make GridTemplateColumns work again

* Update version

* - Fix verified files for DataGrid tests

* - Script optimization
- Take resize handler out of button

* - Rename ShowSortIcon -> IsActiveSortColumn
-Update RemoveSortByColumn logic

* More optimizations and fixes

* - More fine-tunning.
- Add `MultiLine` parameter to grid + styling
- Make `AutoSize` work again

* Fix tests

* - Styling updates
- Set `RowSize` to small to be equal to v4 default

* - Don't use dynamic row size for now.
- Process review comments

* Fix tests

* More style updates

* - Re-add separate header buttons
- Fix some samples
- Position resize handle better
- Always put sort/filter indicators behind header text
- Add comments to public methods

* Fix merge issues

* Change icons in grid to size 20 (nice in the middel of Aspire (16) and our default (24)

* Fix tests/verified files

* Fix virtualized grid row height

* Fix column resizing when in rtl mode

* - Fix button width when no filter button
- Add tabindex to cells
- Fix resize handle pos when rtl
-WIP: use cursor keys to go through cells

* - Update example,
- Update rendering for non button column headee
- Fix multiline height issue

* Fix tests

* - Process review comments

* - Fix keyboard navigation in DataGrid

* Menu work

* Fix DataGrid Header menu

* Add a start padding for the first header cell

* Process compiler hint

* - Fix remote data example
- Clean Issue tester
- Remove commented out code
- Fix AutoSize tou use `px` instead of `fr`

* Don't use AutoFocus on demo page

* Fix scroll on up/down arrow keypress

* Fix Select All not aligned correctly

* Add Index to ColumnBase

* Fix tests
  • Loading branch information
vnbaaij authored Nov 29, 2024
1 parent b0f81d7 commit c9ce550
Show file tree
Hide file tree
Showing 44 changed files with 1,142 additions and 923 deletions.
6 changes: 3 additions & 3 deletions examples/Demo/Shared/Components/ApiDocumentation.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
string header = Properties.Any(x => x.IsParameter) ? "Parameters" : "Properties";
<h4 id="@(_id + "_properties")">@header</h4>
<div class="docgrid">
<FluentDataGrid Items="@this.Properties.AsQueryable()" GridTemplateColumns="1fr 1fr 0.7fr 2fr">
<FluentDataGrid Items="@this.Properties.AsQueryable()" GridTemplateColumns="1fr 1fr 0.7fr 2fr" MultiLine="true">
<TemplateColumn Title="Name"><code>@context.Name</code></TemplateColumn>
<TemplateColumn Title="Type">
@context.Type
Expand Down Expand Up @@ -82,7 +82,7 @@
{
<h4 id="@(_id)_callbacks">EventCallbacks</h4>
<div class="docgrid">
<FluentDataGrid Items="@this.Events.AsQueryable()" GridTemplateColumns="1fr 1fr 1fr">
<FluentDataGrid Items="@this.Events.AsQueryable()" GridTemplateColumns="1fr 1fr 1fr" MultiLine="true">
<TemplateColumn Title="Name"><code>@context.Name</code></TemplateColumn>
<PropertyColumn Property="@(c => c.Type)" />
<TemplateColumn Title="Description">
Expand All @@ -98,7 +98,7 @@
{
<h4 id="@(_id)_methods">Methods</h4>
<div class="docgrid">
<FluentDataGrid Items="@this.Methods.AsQueryable()" GridTemplateColumns="1fr 1fr 1fr 1fr">
<FluentDataGrid Items="@this.Methods.AsQueryable()" GridTemplateColumns="1fr 1fr 1fr 1fr" MultiLine="true">
<TemplateColumn Title="Name"><code>@context.Name</code></TemplateColumn>
<TemplateColumn Title="Parameters">
@foreach (var param in @context.Parameters)
Expand Down
68 changes: 66 additions & 2 deletions examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,11 @@
This is rendered automatically if <see cref="P:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.HeaderCellItemTemplate" /> is not used.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.Index">
<summary>
Gets or sets the index (1-based) of the column
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.ColumnBase`1.Class">
<summary>
Gets or sets the an optional CSS class name.
Expand Down Expand Up @@ -1858,6 +1863,14 @@
is small or if you are using pagination.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.OverscanCount">
<summary>
This is applicable only when using <see cref="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.Virtualize"/>. It defines how many additional items will be rendered
before and after the visible region to reduce rendering frequency during scrolling. While higher values can improve
scroll smoothness by rendering more items off-screen, they can also increase initial load times. Finding a balance
based on your data set size and user experience requirements is recommended. The default value is 3.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.ItemSize">
<summary>
This is applicable only when using <see cref="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.Virtualize"/>. It defines an expected height in pixels for
Expand Down Expand Up @@ -2002,6 +2015,16 @@
Sets <see cref="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.GridTemplateColumns"/> to automatically fit the columns to the available width as best it can.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.RowSize">
<summary>
Gets or sets the size of each row in the grid based on the <see cref="T:Microsoft.FluentUI.AspNetCore.Components.DataGridRowSize"/> enum.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.MultiLine">
<summary>
Gets or sets a value indicating whether the grid should allow multiple lines of text in cells.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.SaveStateInUrl">
<summary>
Gets or sets a value indicating whether the grid should save its paging state in the URL.
Expand All @@ -2013,6 +2036,11 @@
</summary>
<remarks>Only relevant when <see cref="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.SaveStateInUrl"/> is set to <see langword="true"/> on multiple grids on a single page.</remarks>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.AutoFocus">
<summary>
Gets or sets a value indicating whether the grids' first cell should be focused.
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1.#ctor">
<summary>
Constructs an instance of <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1"/>.
Expand Down Expand Up @@ -2168,7 +2196,7 @@
Gets or sets the owning <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow`1"/> component.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridCell`1.GridContext">
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridCell`1.InternalGridContext">
<summary>
Gets or sets the owning <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1"/> component
</summary>
Expand All @@ -2178,6 +2206,11 @@
Gets a reference to the column that this cell belongs to.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridCell`1.Grid">
<summary>
Gets a reference to the enclosing <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1" />.
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridCell`1.HandleOnCellClickAsync">
<summary />
</member>
Expand Down Expand Up @@ -2207,11 +2240,16 @@
Gets or sets the content to be rendered inside the component.
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow`1.Owner">
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow`1.InternalGridContext">
<summary>
Gets or sets the owning <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1"/> component
</summary>
</member>
<member name="P:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow`1.Grid">
<summary>
Gets a reference to the enclosing <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1" />.
</summary>
</member>
<member name="M:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow`1.HandleOnRowClickAsync(System.String)">
<summary />
</member>
Expand Down Expand Up @@ -13430,6 +13468,32 @@
Resize datagrid columns by exact pixel values
</summary>
</member>
<member name="T:Microsoft.FluentUI.AspNetCore.Components.DataGridRowSize">
<summary>
The height of each <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow`1"/> in a <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1"/>.
Values are in pixels.
</summary>
</member>
<member name="F:Microsoft.FluentUI.AspNetCore.Components.DataGridRowSize.Small">
<summary>
Small row height (default)
</summary>
</member>
<member name="F:Microsoft.FluentUI.AspNetCore.Components.DataGridRowSize.Medium">
<summary>
Medium row height
</summary>
</member>
<member name="F:Microsoft.FluentUI.AspNetCore.Components.DataGridRowSize.Smaller">
<summary>
Smaller row height
</summary>
</member>
<member name="F:Microsoft.FluentUI.AspNetCore.Components.DataGridRowSize.Large">
<summary>
Large row height
</summary>
</member>
<member name="T:Microsoft.FluentUI.AspNetCore.Components.DataGridRowType">
<summary>
The type of <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGridRow`1"/> in a <see cref="T:Microsoft.FluentUI.AspNetCore.Components.FluentDataGrid`1"/>.
Expand Down
2 changes: 1 addition & 1 deletion examples/Demo/Shared/Pages/DataGrid/DataGridPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ fluent-data-grid-row:has([row-selected]) {

<DemoSection Title="Multiline text content" Component="@typeof(DataGridMultilineText)">
<Description>
Example of using the <code>Class</code> parameter to style parts of the grid. Note that the class used in the example (<code>multiline-text</code>) has been added to the FluentDataGridCell css.
Set the grid parameter <code>MultiLine</code> to true when you have cells in your data that will take up more than a single line.
</Description>
</DemoSection>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<FluentGrid Spacing="4">
<FluentGridItem xs="12">
<h4>With auto-fit</h4>
<FluentDataGrid Items="@people" AutoFit="true">
<FluentDataGrid Items="@people" Style="width: 100%;" AutoFit="true">
<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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,51 +10,52 @@

}


<FluentToolbar>
<FluentRadioGroup Name="rt" @bind-Value="@_resizeType" Label="Resize type">
<FluentRadio Value="@((DataGridResizeType?)null)">None</FluentRadio>
<FluentRadio Value="@DataGridResizeType.Discrete">Discrete</FluentRadio>
<FluentRadio Value="@DataGridResizeType.Exact">Exact</FluentRadio>
</FluentRadioGroup>
<FluentSpacer Width="25"/>
<FluentCheckbox @bind-Value="@_showActionsMenu" Label="Use menu for column actions" />
<FluentRadioGroup Name="rt" @bind-Value="@_resizeType" Label="Resize type">
<FluentRadio Value="@((DataGridResizeType?)null)">None</FluentRadio>
<FluentRadio Value="@DataGridResizeType.Discrete">Discrete</FluentRadio>
<FluentRadio Value="@DataGridResizeType.Exact">Exact</FluentRadio>
</FluentRadioGroup>
<FluentSpacer Width="25" />
<FluentCheckbox @bind-Value="@_showActionsMenu" Label="Use menu for column actions" />
</FluentToolbar>
<FluentDataGrid Items="@FilteredItems"
ResizableColumns=true
ResizeType="@_resizeType"
HeaderCellAsButtonWithMenu="_showActionsMenu"
Pagination="@pagination"
TGridItem="Country"
OnRowFocus="HandleRowFocus"
GridTemplateColumns="0.2fr 1fr 0.2fr 0.2fr 0.2fr 0.2fr"
Style="height: 405px; overflow:auto;"
ShowHover="true">
<TemplateColumn Title="Rank" SortBy="@rankSort" Align="Align.Center">
<img class="flag" src="_content/FluentUI.Demo.Shared/flags/@(context.Code).svg" alt="Flag of @(context.Code)" />
</TemplateColumn>
<PropertyColumn Property="@(c => c.Name)" InitialSortDirection=SortDirection.Descending Sortable="true" IsDefaultSortColumn=true Comparer="@StringLengthComparer.Instance" Filtered="!string.IsNullOrWhiteSpace(nameFilter)">
<ColumnOptions>
<div class="search-box">
<FluentSearch type="search" Autofocus=true @bind-Value=nameFilter @oninput="HandleCountryFilter" AfterBindValue="HandleClear" Placeholder="Country name..." />
</div>
</ColumnOptions>
</PropertyColumn>
@* <TemplateColumn Title="Name" InitialSortDirection=SortDirection.Descending SortBy="@nameSort" IsDefaultSortColumn=true Filtered="!string.IsNullOrWhiteSpace(nameFilter)">
<ColumnOptions>
<div class="search-box">
<div style="height: 400px; overflow-x:auto; display:flex;">
<FluentDataGrid Items="@FilteredItems"
ResizableColumns=true
ResizeType="@_resizeType"
HeaderCellAsButtonWithMenu="_showActionsMenu"
Pagination="@pagination"
TGridItem="Country"
OnRowFocus="HandleRowFocus"
GridTemplateColumns="0.2fr 1fr 0.2fr 0.2fr 0.2fr 0.2fr"
ShowHover="true">
<TemplateColumn Title="Rank" Sortable="true" SortBy="@rankSort" Align="Align.Center">
<img class="flag" src="_content/FluentUI.Demo.Shared/flags/@(context.Code).svg" alt="Flag of @(context.Code)" />
</TemplateColumn>
<PropertyColumn Property="@(c => c.Name)" InitialSortDirection=SortDirection.Descending Sortable="true" IsDefaultSortColumn=true Comparer="@StringLengthComparer.Instance" Filtered="!string.IsNullOrWhiteSpace(nameFilter)">
<ColumnOptions>
<div class="search-box">
<FluentSearch type="search" Autofocus=true @bind-Value=nameFilter @oninput="HandleCountryFilter" @bind-Value:after="HandleClear" Placeholder="Country name..." />
</div>
</ColumnOptions>
</PropertyColumn>
@* <TemplateColumn Title="Name" InitialSortDirection=SortDirection.Descending SortBy="@nameSort" IsDefaultSortColumn=true Filtered="!string.IsNullOrWhiteSpace(nameFilter)">
<ColumnOptions>
<div class="search-box">
<FluentSearch type="search" Autofocus=true @bind-Value=nameFilter @oninput="HandleCountryFilter" @bind-Value:after="HandleClear" Placeholder="Country name..." />
</div>
</ColumnOptions>
<ChildContent>
@(context.Name)
</ChildContent>
</TemplateColumn> *@
<PropertyColumn Property="@(c => c.Medals.Gold)" Sortable="true" Align="Align.Start" />
<PropertyColumn Property="@(c => c.Medals.Silver)" Sortable="true" Align="Align.Center" />
<PropertyColumn Property="@(c => c.Medals.Bronze)" Sortable="true" Align="Align.End" />
<PropertyColumn Property="@(c => c.Medals.Total)" Sortable="true" Align="Align.End" />
</FluentDataGrid>

</div>
</ColumnOptions>
<ChildContent>
@(context.Name)
</ChildContent>
</TemplateColumn> *@
<PropertyColumn Property="@(c => c.Medals.Gold)" Sortable="true" Align="Align.Start" />
<PropertyColumn Property="@(c => c.Medals.Silver)" Sortable="true" Align="Align.Center" />
<PropertyColumn Property="@(c => c.Medals.Bronze)" Sortable="true" Align="Align.End" />
<PropertyColumn Property="@(c => c.Medals.Total)" Sortable="true" Align="Align.End" />
</FluentDataGrid>
</div>

<FluentPaginator State="@pagination">
<SummaryTemplate>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<FluentDataGrid Items="@people">
<FluentDataGrid Items="@people" MultiLine="true">
<PropertyColumn Property="@(p => p.PersonId)" Sortable="true" />
<PropertyColumn Property="@(p => p.Name)" Sortable="true" />
<PropertyColumn Property="@(p => p.Description)" Sortable="true" Class="multiline-text" />
<PropertyColumn Property="@(p => p.Description)" Sortable="true" />
</FluentDataGrid>

@code {
Expand All @@ -13,4 +13,4 @@
new Person(10944, "António Langa", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
new Person(11203, "Julie Smith","Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."),
}.AsQueryable();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div style="height: 400px; overflow-y: scroll;">
<FluentDataGrid @ref="grid" Items=@items GridTemplateColumns="1fr 1fr 1fr 1fr" Style="height: 100%;">
<FluentDataGrid @ref="grid" Items=@items GridTemplateColumns="1fr 1fr 1fr 1fr">
<ChildContent>
<PropertyColumn Property="@(c => c.Item1)" Sortable="true" />
<PropertyColumn Property="@(c => c.Item2)" />
Expand Down Expand Up @@ -53,7 +53,7 @@
grid?.SetLoadingState(true);
items = null;

await Task.Delay(2500);
await Task.Delay(1500);

items = GenerateSampleGridData(100);
grid?.SetLoadingState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
@inject NavigationManager NavManager

<div style="height: 434px; overflow:auto;" tabindex="-1">
<FluentDataGrid style="height: 100%;" Loading="@(numResults == null)" ItemsProvider="foodRecallProvider" OnRowDoubleClick="@(()=>DemoLogger.WriteLine("Row double clicked!"))" Virtualize="true" ItemSize="46" GenerateHeader="GenerateHeaderOption.Sticky" TGridItem="FoodRecall" >
<FluentDataGrid
Loading="@(numResults == null)"
ItemsProvider="foodRecallProvider"
OnRowDoubleClick="@(()=>DemoLogger.WriteLine("Row double clicked!"))"
Virtualize="true"
ItemSize="46"
GenerateHeader="GenerateHeaderOption.Sticky"
TGridItem="FoodRecall" >
<PropertyColumn Title="ID" Property="@(c => c!.Event_Id)" />
<PropertyColumn Property="@(c => c!.State)" Style="color: #af5f00 ;" />
<PropertyColumn Property="@(c => c!.City)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<FluentDataGrid Style="min-width: max-content;" Items="@people">
<PropertyColumn Property="@(p => p.PersonId)" Sortable="true" />
<PropertyColumn Property="@(p => p.Name)" Sortable="true" />
<PropertyColumn Property="@(p => p.Description)" Sortable="true" Class="multiline-text" />
<PropertyColumn Property="@(p => p.Description)" Sortable="true" Style="text-overflow: unset; overflow: visible;" />
</FluentDataGrid>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@inject DataSource Data

<FluentDataGrid Items="@Data.People" style="width: 600px;">
<FluentDataGrid Items="@Data.People" style="width: 600px;" RowSize="@DataGridRowSize.Medium">
<TemplateColumn Title="Person" SortBy="@sortByName">
<div class="flex items-center">
<img class="flag" src="_content/FluentUI.Demo.Shared/flags/@(context.CountryCode.ToLower()).svg" alt="Flag of @(context.CountryCode)" />
Expand Down Expand Up @@ -28,4 +28,4 @@
void Bonus(Person p) => message = $"You want to give {p.FirstName} {p.LastName} a regular bonus";

void DoubleBonus(Person p) => message = $"You want to give {p.FirstName} {p.LastName} a double bonus";
}
}
Loading

0 comments on commit c9ce550

Please sign in to comment.