Searching for a way to be able to
reselect the row in the grid, after insert or edit, I found this link
here with your provided solution. It worked fine until I found that if the grid is sorted in one column (for example "Name") whose cell value is edited (for example from "Anna" to "Zanna") forcing the row outside the initial page count it stays in an indefinite loop. It is easy to see that this is because the Grid.PageSettings.CurrentPage gives a number smaller than the real quantity of pages. On your code, for example, it returns only 7 but the total pages according to the navigator at the botton is 13
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Buttons
<SfButton OnClick="DataHandler" Content="Navigate"></SfButton>
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true">
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid { get; set; }
public bool ContinuePaging = true;
public bool InitialRender { get; set; }
public int Value = 1015; // consider that value your querystring contains
public List<Order> Orders { get; set; }
public async Task DataHandler()
{
var PageCount = Grid.PageSettings.PageCount - 1;
ContinuePaging = true;
var CurrentPage = Grid.PageSettings.CurrentPage;
await Grid.GoToPage(CurrentPage);
for (int i = 1; i <= PageCount; i++)
{
List<Order> Rows = await Grid.GetCurrentViewRecords(); // returns the current view data
for (int j = 0; j < Grid.PageSettings.PageSize; j++)
{
if (j < Rows.Count && Rows[j].OrderID == Value)
{
await Grid.SelectRow(j);
ContinuePaging = false; // prevent the default navigation
break;
}
}
if (ContinuePaging)
{
if (i >= PageCount)
{
i = 0;
}
await Grid.GoToPage(i + 1);
await Task.Delay(200);
}
}
}
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 150).Select(x => new Order()
{
OrderID = 1000 + x,
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID", "Nancy", "Andrew", "Davolia", "Joseph", "Curten", "VINET", "TOMPS", "WELLI", "HANAR" })[new Random().Next(14)],
Freight = 2.1 * x,
OrderDate = (new DateTime[] { new DateTime(2010, 5, 1), new DateTime(2010, 5, 2), new DateTime(2010, 5, 3), })[new Random().Next(3)],
}).ToList();
}
public class Order
{
public int? OrderID { get; set; }
public string CustomerID { get; set; }
public DateTime? OrderDate { get; set; }
public double? Freight { get; set; }
}
}