|
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true">
<GridEvents DataBound="DataHandler" TValue="Order"></GridEvents>
<GridColumns>
. . . . . . . . .
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid { get; set; }
public bool ContinuePaging = true;
public bool InitialRender { get; set; }
public int Value = 1055; // consider that value your querystring contains
public List<Order> Orders { get; set; }
public async Task DataHandler()
{
if (InitialRender) // to handled during the initial rendering of Grid
{
InitialRender = false;
for (int i = 1; i <= Grid.PageSettings.PageCount; i++)
{
List<Order> Rows = await Grid.GetCurrentViewRecords(); // returns the current view data
for (int j = 0; j < Grid.PageSettings.PageSize; j++)
{
if (Rows[j].OrderID == Value)
{
await Grid.SelectRow(j);
ContinuePaging = false; // prevent the default navigation
}
}
if (ContinuePaging)
{
await Grid.GoToPage(i + 1); // if current page does not contain the record navigate to next page.
}
}
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
InitialRender = true;
}
}
}
|
|
<SfButton OnClick="DataHandler" Content="Navigate"></SfButton>
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true">
. . . . . .. .
</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()
{
ContinuePaging = true;
var CurrentPage = Grid.PageSettings.CurrentPage;
await Grid.GoToPage(CurrentPage);
var PageCount = Grid.PageSettings.PageCount - 1;
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);
}
}
}
}
|