-
Notifications
You must be signed in to change notification settings - Fork 461
[DataGrid] Provide alternate way to refresh when working with remote data #3423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4ac14ea
Fix DataGrid remote data calling API multiple times.
EMotaSouza b387814
Merge branch 'dev' into dev
vnbaaij 5fe92d5
Merge branch 'dev' into dev
vnbaaij 329feea
Add vnbaaij requests
EMotaSouza 5de28fa
Merge branch 'dev' of https://github.com/EvandroMoSou/fluentui-blazorβ¦
EMotaSouza 8081f75
Merge branch 'dev' into dev
vnbaaij File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
106 changes: 106 additions & 0 deletions
106
examples/Demo/Shared/Pages/DataGrid/Examples/DataGridRemoteData2.razor
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| ο»Ώ@using Microsoft.FluentUI.AspNetCore.Components | ||
|
|
||
| @inject HttpClient Http | ||
| @inject NavigationManager NavManager | ||
|
|
||
| <FluentAccordion> | ||
| <FluentAccordionItem Heading="Filter(s)" Expanded="true"> | ||
| <FluentIcon Value="@(new Icons.Regular.Size20.FilterAdd())" Color="@Color.Neutral" Slot="start" /> | ||
| <FluentGrid Spacing="1" Justify="JustifyContent.FlexStart" Style="padding: 5px;"> | ||
| <FluentGridItem xs="12" sm="6" md="4"> | ||
| <FluentTextField @bind-Value=_stateFilter Label="State Filter"></FluentTextField> | ||
| </FluentGridItem> | ||
| </FluentGrid> | ||
| <FluentStack Orientation="Orientation.Horizontal" HorizontalAlignment="HorizontalAlignment.End"> | ||
| <FluentButton IconStart="@(new Icons.Regular.Size16.Broom())" | ||
| Disabled="loading" | ||
| OnClick="ClearFilters"> | ||
| Clear | ||
| </FluentButton> | ||
| <FluentButton IconStart="@(new Icons.Regular.Size16.ArrowClockwise())" | ||
| Appearance="Appearance.Accent" | ||
| Loading="loading" | ||
| OnClick="DataGridRefreshDataAsync"> | ||
| Search | ||
| </FluentButton> | ||
| </FluentStack> | ||
| </FluentAccordionItem> | ||
| </FluentAccordion> | ||
| <br /> | ||
| <div style="height: 370px; overflow:auto;" tabindex="-1"> | ||
| <FluentDataGrid @ref="dataGrid" | ||
| Items="foodRecallItems" | ||
| RefreshItems="RefreshItemsAsync" | ||
| OnRowDoubleClick="@(()=>DemoLogger.WriteLine("Row double clicked!"))" | ||
| ItemSize="46" | ||
| GenerateHeader="GenerateHeaderOption.Sticky" | ||
| TGridItem="FoodRecall" | ||
| Loading="loading" | ||
| Pagination="pagination"> | ||
| <PropertyColumn Title="ID" Property="@(c => c!.Event_Id)" /> | ||
| <PropertyColumn Property="@(c => c!.State)" Style="color: #af5f00 ;" /> | ||
| <PropertyColumn Property="@(c => c!.City)" /> | ||
| <PropertyColumn Title="Company" Property="@(c => c!.Recalling_Firm)" Tooltip="true" /> | ||
| <PropertyColumn Property="@(c => c!.Status)" /> | ||
| <PropertyColumn Title="Termination Date" Property="@(c => c!.Termination_Date)" SortName="termination_date" Sortable="true" /> | ||
| <TemplateColumn Title="Actions" Align="@Align.End"> | ||
| <FluentButton aria-label="Edit item" IconEnd="@(new Icons.Regular.Size16.Edit())" OnClick="@(() => DemoLogger.WriteLine("Edit clicked"))" /> | ||
| <FluentButton aria-label="Delete item" IconEnd="@(new Icons.Regular.Size16.Delete())" OnClick="@(() => DemoLogger.WriteLine("Delete clicked"))" /> | ||
| </TemplateColumn> | ||
| </FluentDataGrid> | ||
| </div> | ||
| <FluentPaginator State="@pagination" /> | ||
|
|
||
| @code { | ||
|
|
||
| FluentDataGrid<FoodRecall> dataGrid = default!; | ||
| IQueryable<FoodRecall> foodRecallItems = default!; | ||
| bool loading = true; | ||
| PaginationState pagination = new PaginationState { ItemsPerPage = 10 }; | ||
| string _stateFilter = "NY"; | ||
|
|
||
| protected async Task RefreshItemsAsync(GridItemsProviderRequest<FoodRecall> req) | ||
| { | ||
| loading = true; | ||
| await InvokeAsync(StateHasChanged); | ||
|
|
||
| var filters = new Dictionary<string, object?> | ||
| { | ||
| { "skip", req.StartIndex }, | ||
| { "limit", req.Count }, | ||
| }; | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(_stateFilter)) | ||
| filters.Add("search", $"state:{_stateFilter}"); | ||
|
|
||
| if (req.SortByColumn != null) | ||
| filters.Add("sort", req.SortByColumn.SortName + (req.SortByAscending ? ":asc" : ":desc")); | ||
|
|
||
| var url = NavManager.GetUriWithQueryParameters("https://api.fda.gov/food/enforcement.json", filters); | ||
|
|
||
| var response = await Http.GetFromJsonAsync<FoodRecallQueryResult>(url); | ||
|
|
||
| // Simulate a slow data retrieval process | ||
| if (req.Count is null) | ||
| { | ||
| await Task.Delay(2500); | ||
| } | ||
|
|
||
| foodRecallItems = response!.Results.AsQueryable(); | ||
| await pagination.SetTotalItemCountAsync(response!.Meta.Results.Total); | ||
|
|
||
| loading = false; | ||
| await InvokeAsync(StateHasChanged); | ||
| } | ||
|
|
||
| public void ClearFilters() | ||
| { | ||
| _stateFilter = null; | ||
|
Check warning on line 98 in examples/Demo/Shared/Pages/DataGrid/Examples/DataGridRemoteData2.razor
|
||
| } | ||
|
|
||
| public async Task DataGridRefreshDataAsync() | ||
| { | ||
| await dataGrid.RefreshDataAsync(true); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.