Why OnInitializedAsync Invoke 2 time #3217
-
Why OnInitializedAsync Invoke 2 time protected override async Task OnInitializedAsync()
{
Debug.WriteLine("OnInitializedAsync");
if (_dataGrid is null)
{
SelectedItems = new List<CustomerDto>();
}
else
{
SelectedItems = _dataGrid!.Items!.Where(p => p.Selected).ToList();
}
_gridItemProvider = GridItemProvider;
}
private async ValueTask<GridItemsProviderResult<CustomerDto>> GridItemProvider(GridItemsProviderRequest<CustomerDto> request)
{
Debug.WriteLine("Start Call GridItemProvider");
if (!string.IsNullOrWhiteSpace(_nameFilter))
{
_filter = dto => dto.Name.Contains(_nameFilter) || dto.Code.ToString().Contains(_nameFilter) || dto.Description.Contains(_nameFilter);
}
var sort = new Dictionary<string, AppSortOrder>();
foreach (var sortByProperty in request.GetSortByProperties())
{
sort.Add(sortByProperty.PropertyName, sortByProperty.Direction == SortDirection.Auto
? AppSortOrder.UnSet
: sortByProperty.Direction == SortDirection.Ascending
? AppSortOrder.Ascending
: AppSortOrder.Descending);
}
var result = await Mediator!.Send(new CustomerGetAllExactRequest
{
Skip = request.StartIndex,
Take = request.Count ?? 1,
OrderBy = sort,
Filter = _filter,
CalcTotal = true
});
if (!result.IsSuccess) return new GridItemsProviderResult<CustomerDto>();
for (var index = 0; index < result.Data!.Count; index++)
{
var customerDto = result.Data![index];
customerDto.RowIndex = request.StartIndex + index + 1;
}
//_numResults = 0;
//_numResults = result.TotalCount;
Debug.WriteLine("End Call GridItemProvider");
return GridItemsProviderResult.From(result.Data!, result.TotalCount);
} <FluentCard MinimalStyle="true" Width="100%" Height="100%">
<div class="search" style="width: 100%">
<FluentToolbar id="toolbar-fluent-components" Style="width: 100%">
<FluentButton Color="Color.Accent" Title="@AppStringResource.CustomerStrings.CreateCustomerPageTitle" Appearance="Appearance.Neutral" IconStart="@(new Size20.News())" OnClick="OnNewClick">@AppStringResource.New</FluentButton>
<FluentSearch Autofocus=true
@bind-Value=_nameFilter
@oninput="HandleFilter"
@bind-Value:after="HandleClearFilter"
Placeholder="@AppStringResource.Search"
AutoComplete="true"
Immediate="true"
ImmediateDelay="250"
Maxlength="100"
Minlength="2"/>
</FluentToolbar>
</div>
<FluentDataGrid TGridItem="CustomerDto"
@ref="_dataGrid"
Virtualize="true"
ResizableColumns="false"
ColumnResizeLabels="@UiHelper.ColumnResizeLabels"
ColumnSortLabels="@UiHelper.ColumnSortLabels"
ItemKey="dto => { return dto.Id; }"
ShowHover="true"
GenerateHeader="GenerateHeaderOption.Sticky"
ItemsProvider="_gridItemProvider"
ItemSize="46"
Class="fluentDataGrid">
<ChildContent>
<PropertyColumn Property="@(p => p.RowIndex)" Width="7rem" Format="N0"/>
<PropertyColumn Property="@(p => p.Name)" Sortable="true" Filtered="true"IsDefaultSortColumn="true" InitialSortDirection="SortDirection.Ascending"/>
<PropertyColumn Property="@(p => p.Code)" Sortable="true" Filtered="true"/>
<PropertyColumn Property="@(p => p.Credit)" Sortable="true" Filtered="true"/>
<PropertyColumn Property="@(p => p.UsedCredit)" Sortable="true" Filtered="true"/>
<PropertyColumn Property="@(p => p.RemainingCredit)" Sortable="true" Filtered="true"/>
<TemplateColumn Title="@AppStringResource.CustomerStrings.CreditThresholdLimitPercentage" Sortable="true" Filtered="true" SortBy="@sortByCreditThresholdLimitPercentage" >
<FluentLabel>@( $"{context.CreditThresholdLimitPercentage}%")</FluentLabel>
</TemplateColumn>
<PropertyColumn Property="@(p => p.PhoneNumber)" Sortable="true" Filtered="true"/>
<PropertyColumn Property="@(p => p.Address)" Sortable="true" Filtered="true"/>
<PropertyColumn Property="@(p => p.Description)" Sortable="true" Filtered="true"/>
<TemplateColumn Title="@AppStringResource.Operations" Align="@Align.Center" Width="10rem">
<FluentButton Title="@AppStringResource.UpdateTooltip" IconEnd="@(new Size16.Edit().WithColor(Color.Info))" OnClick="async () => { await OnUpdateAsync(context); }"/>
<FluentButton Title="@AppStringResource.Delete" IconEnd="@(new Size16.Delete().WithColor(Color.Error))" OnClick="async () => { await OnDeleteAsync(context.Id); }"/>
</TemplateColumn>
</ChildContent>
<EmptyContent>
<FluentIcon Value="@(new Size24.Crown())" Color="@Color.Accent"/> @AppStringResource.NoRecords
</EmptyContent>
<LoadingContent>
<FluentStack Orientation="Orientation.Vertical" HorizontalAlignment="HorizontalAlignment.Center">
@AppStringResource.Loading<br/>
<FluentProgress Width="240px"/>
</FluentStack>
</LoadingContent>
</FluentDataGrid>
<div style="margin-top: 0.5rem">
<p> @UiHelper.GetFooterCountSummary(_numResults ?? 0)</p>
</div>
</FluentCard> OnInitializedAsync |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, Please see comments and discussions in #1514. #1982 and #2057 If server, than it might just be a case of prerendering taking place and the method is called twice because of that |
Beta Was this translation helpful? Give feedback.
Hi, Please see comments and discussions in #1514. #1982 and #2057
If server, than it might just be a case of prerendering taking place and the method is called twice because of that