-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataGrid] Make SelectColumn work when using ItemsProvider (#2060)
* Fix #2055 by including ItemsProvider in the logic * Also fix #2053 by excluding SelectColumns from GridTemplateColumns/Width check
- Loading branch information
Showing
6 changed files
with
75 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,52 @@ | ||
@page "/IssueTester" | ||
|
||
@page "/TestSelectColumns" | ||
|
||
<FluentDataGrid ItemsProvider="PersonProvider" ShowHover="true" TGridItem="Person" Pagination="@pagination" GridTemplateColumns="50px 1fr 2fr 1fr"> | ||
<SelectColumn TGridItem="Person" | ||
SelectMode="DataGridSelectMode.Multiple" | ||
Property="@(e => e.Selected)" | ||
OnSelect="@(e => e.Item.Selected = e.Selected)" | ||
SelectAll="@(PeopleList.All(p => p.Selected))" | ||
SelectAllChanged="@(all => PeopleList.ToList().ForEach(p => p.Selected = (all == true)))" /> | ||
<PropertyColumn Property="@(p => p.PersonId)" Title="ID" Sortable="true" /> | ||
<PropertyColumn Property="@(p => p.Name)" Sortable="true" /> | ||
<PropertyColumn Property="@(p => p.BirthDate)" Format="yyyy-MM-dd" Sortable="true" /> | ||
</FluentDataGrid> | ||
<FluentPaginator State="@pagination" /> | ||
|
||
<div> | ||
<b>Peoples:</b> | ||
@String.Join("; ", PeopleList.Where(p => p.Selected).Select(p => p.Name)) | ||
</div> | ||
|
||
@code { | ||
PaginationState pagination { get; set; } = new PaginationState() { ItemsPerPage = 10 }; | ||
|
||
public record Person(int PersonId, string Name, DateOnly BirthDate) | ||
{ | ||
public bool Selected { get; set; } | ||
}; | ||
|
||
public static List<Person> PeopleList = 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)), | ||
new Person(10895, "Jean 2 Martin", new DateOnly(1985, 3, 16)), | ||
new Person(10944, "António 2 Langa", new DateOnly(1991, 12, 1)), | ||
new Person(11203, "Julie 2 Smith", new DateOnly(1958, 10, 10)), | ||
new Person(11205, "Nur 2 Sari", new DateOnly(1922, 4, 27)), | ||
new Person(11898, "Jose 2 Hernandez", new DateOnly(2011, 5, 3)), | ||
new Person(12130, "Kenji 2 Sato", new DateOnly(2004, 1, 9)), | ||
}; | ||
|
||
private async ValueTask<GridItemsProviderResult<Person>> PersonProvider(GridItemsProviderRequest<Person> req) | ||
Check warning on line 47 in examples/Demo/Shared/Pages/Lab/IssueTester.razor
|
||
{ | ||
var subList = PeopleList.Skip(req.StartIndex).Take(req.Count ?? PeopleList.Count).ToList(); | ||
return GridItemsProviderResult.From(subList, PeopleList.Count); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters