Hello,
I have a PageNumber state and I am trying to set the PageNumber using GoToPage(), when user comes back to the page. I am following the example mentioned here. (https://blazor.radzen.com/datagrid-loaddata). But My LoadData method is not hitting and I do not see any data in the grid. When I move my API call to OnInitializeAsync and remove the LoadData on the RadzenDataGrid, I could able to see the data in the grid.
Please let me know where I am doing wrong?
@if (_clients != null)
{
<RadzenButton Text="Add Client" Icon="add_circle" Click="@(args => CreateClient())" class="rz-my-3" />
<RadzenDataGrid @ref="_grid" AllowFiltering="true" FilterPopupRenderMode="PopupRenderMode.OnDemand" AllowPaging="true" PageSize="10" AllowSorting="true"
AllowMultiColumnSorting="true" Data="@_clients" TItem="ClientDTO" LoadData="@OnLoadData" Count="@_dataCount">
<Columns>
<RadzenDataGridColumn TItem="ClientDTO" Title="#" Filterable="false" Sortable="false" TextAlign="TextAlign.Center">
<Template Context="data">
@(_clients.IndexOf(data) + 1)
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ClientDTO" Property="Client" Title="Name" />
<RadzenDataGridColumn TItem="ClientDTO" Property="OfficeAddress" Title="Address" />
<RadzenDataGridColumn TItem="ClientDTO" Property="OfficePhone" Title="Phone" />
<RadzenDataGridColumn TItem="ClientDTO" Property="Speciality" Title="Speciality" />
<RadzenDataGridColumn TItem="ClientDTO" Property="ServiceIsactive" Title="Active" Filterable="false" />
<RadzenDataGridColumn TItem="ClientDTO" Title="Action" Frozen="true" Sortable="false" Filterable="false" TextAlign="TextAlign.Center">
<Template Context="data">
<RadzenButton ButtonStyle="ButtonStyle.Info" Variant="Variant.Flat" Shade="Shade.Lighter" Icon="info" class="m-1" Click=@(() => EditClient(data.ClientID) ) Text="EDIT" />
</Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
}
else
{
<Loading Text="Loading" />
}
@code {
private RadzenDataGrid<ClientDTO> _grid;
private List<ClientDTO> _clients;
private int _dataCount = 0;
//protected override async Task OnInitializedAsync()
//{
// Dispatcher.Dispatch(new GetPageNumberAction());
// var _clientResult = await Http.GetFromJsonAsync<IEnumerable<ClientDTO>>("api/Client");
// _clients = _clientResult.ToList();
//}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
{
await _grid.GoToPage(ClientState.Value.PageNumber);
}
}
async Task OnLoadData(LoadDataArgs args)
{
var _clientResult = await Http.GetFromJsonAsync<IEnumerable<ClientDTO>>("api/Client");
_clients = _clientResult.Skip(args.Skip.Value).Take(args.Top.Value).ToList();
_dataCount = _clients.Count();
int _currentPage = _grid.CurrentPage;
if (ClientState.Value.PageNumber != _grid.CurrentPage)
{
Dispatcher.Dispatch(new SetPageNumberAction(_currentPage));
}
}
private void CreateClient()
{
NavManager.NavigateTo($"/client");
}
private void EditClient(Guid uuid)
{
NavManager.NavigateTo($"/client/uuid={uuid}");
}
}