Maciej
January 12, 2025, 10:26pm
1
Hello
Is this a planned feature behavior?
DataGrid:
<RadzenDataGrid @ref=dataGrid Style="max-height: 420px" Data="@dataList" TItem="GrafikNaglowek" EmptyText="Brak danych"
AllowPaging="true" PageSize="6"
AllowSorting="true" AllowFiltering="false" AllowColumnResize="true"
SelectionMode="DataGridSelectionMode.Single"
@bind-Value=@selectedGrafikNaglowek RowSelect="GrafikNaglowek_OnRowSelect"
CellDoubleClick="OnCellDoubleClick" CellContextMenu="@OnCellContextMenu">
Button Test_1 works fine.
But Test_2 - before changing the page it reloads the data (dataList has the same number of rows), the function GoToPage does not work
public async Task Test_1_OnClick()
{
await dataGrid.GoToPage(4);
}
public async Task Test_2_OnClick()
{
dataList = nxPlanowanieDataContext.GrafikNagloweks.Where(x => x.Rodzaj == "P").OrderBy(x => x.Kod);
await dataGrid.Reload();
await dataGrid.GoToPage(4);
}
Regards
Maciej
enchev
January 13, 2025, 8:15am
2
Here is an example how to handle such case using our first demo:
@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore
@inherits DbContextPage
<RadzenButton Text="Test_1" Click="@Test_1_OnClick" />
<RadzenButton Text="Test_2" Click="@Test_2_OnClick" />
<RadzenDataGrid @ref="dataGrid" AllowFiltering="true" AllowColumnResize="true" AllowAlternatingRows="false" FilterMode="FilterMode.Advanced" AllowSorting="true" PageSize="3" AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Left" ShowPagingSummary="true"
Data="@employees" ColumnWidth="300px" LogicalFilterOperator="LogicalFilterOperator.Or" SelectionMode="DataGridSelectionMode.Single" @bind-Value=@selectedEmployees>
<Columns>
<RadzenDataGridColumn Property="@nameof(Employee.EmployeeID)" Filterable="false" Title="ID" Frozen="true" Width="80px" TextAlign="TextAlign.Center" />
<RadzenDataGridColumn Title="Photo" Frozen="true" Sortable="false" Filterable="false" Width="80px" TextAlign="TextAlign.Center">
<Template Context="data">
<RadzenImage Path="@data.Photo" class="rz-gravatar" AlternateText="@(data.FirstName + " " + data.LastName)" />
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn Property="@nameof(Employee.FirstName)" Title="First Name" Frozen="true" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.LastName)" Title="Last Name" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Title)" Title="Job Title" Width="200px" />
<RadzenDataGridColumn Property="@nameof(Employee.TitleOfCourtesy)" Title="Title" Width="120px" />
<RadzenDataGridColumn Property="@nameof(Employee.BirthDate)" Title="Birth Date" FormatString="{0:d}" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.HireDate)" Title="Hire Date" FormatString="{0:d}" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Address)" Title="Address" Width="200px" />
<RadzenDataGridColumn Property="@nameof(Employee.City)" Title="City" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Region)" Title="Region" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.PostalCode)" Title="Postal Code" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Country)" Title="Country" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.HomePhone)" Title="Home Phone" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Extension)" Title="Extension" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Notes)" Title="Notes" Width="300px" />
</Columns>
</RadzenDataGrid>
@code {
IQueryable<Employee> employees;
IList<Employee> selectedEmployees;
RadzenDataGrid<Employee> dataGrid;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
employees = dbContext.Employees;
selectedEmployees = new List<Employee>() { employees.FirstOrDefault() };
}
public async Task Test_1_OnClick()
{
await dataGrid.GoToPage(1);
}
bool reload;
public async Task Test_2_OnClick()
{
employees = await Task.FromResult(dbContext.Employees.Take(8));
reload = true;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (reload)
{
reload = false;
await dataGrid.GoToPage(1);
}
}
}
Maciej
January 13, 2025, 10:40am
3
This method works great
Thanks