Hello,
I want to select one/some entries of a DataGrid by ID that is a route parameter AND using a CustomAdaptor.
Route parameter is working, CustomAdpator Read is working, too!
So how the datagrid can select the object with this ID? Must be working with Paging because I have a huge amount of entries! And the data a generated on serverside by a controller.
Thx much for further help!
|
<SfButton OnClick="DataHandler" Content="Navigate"></SfButton>
<SfGrid TValue="Order" ID="Grid" @ref="Grid" AllowSorting="true" AllowFiltering="true" AllowPaging="true">
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<GridPageSettings PageSize="8"></GridPageSettings>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
…
</GridColumns>
</SfGrid>
@code{
public static List<Order> Orders { get; set; }
public SfGrid<Order> Grid { get; set; }
public bool ContinuePaging = true;
public bool InitialRender { get; set; }
public int Value = 1015;
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);
}
}
} |
Thx for fast reply!
But this solution is impossible because of the huge amount of grid entries and the amount of pages!
In our project the grid has > 20k entries and the amount of pages is ~1k!
I guess I have already tested this solution! Every switch of the page the data are collected from the controller! If the element wanted to be selected is on one of the last pages the algorithm is at least 1k * 200ms plus the time to build the data on the controller! -> I dont want to wait > 3min ;)
The best would to be able to inform the adaptor by ReadAnsyc with some additional information: item index and page index. I have already tested this and its working if I send the ID to the controller by route parameter. But the adaptor is firstly collecting the data of the first page and then switching to the calculated page and index of the item (calculated by controller and send to client as property in a container for the result).
I want to be able to avoid the first step (getting the default first page data) if a component parameter (ID) is set!
That is my current solution:
private async void DataBound(object args) // DataBound handler event
{
if (ID != 0)
{
ID = 0;
await portGrid.GoToPage(MappingSourcePortAdaptor.SelectedItemPage);
await portGrid.SelectRow(MappingSourcePortAdaptor.SelectedItemIndex);
await portGrid.ScrollIntoViewAsync(rowIndex: MappingSourcePortAdaptor.SelectedItemIndex);
}
}
public override async Task<object> ReadAsync(DataManagerRequest dm, string key = null)
{
var container = await LoHiService.GetAllPorts(dm, SelectedId); // method to get items from controller
SelectedItemPage = container.SelectedItemPage;
SelectedItemIndex = container.SelectedItemIndex;
var dr = new DataResult<LoHiPort>() { Count = container.ItemsCount, Result = container.LoHiItems };
var dataResult = GroupData(dm, dr);
return dm.RequiresCounts ? dataResult : (object)dataResult.Result;
}
await portGrid.ScrollIntoViewAsync(rowIndex: MappingSourcePortAdaptor.SelectedItemIndex);
is not working because virtualization is not set to true and cannot be set to true because grouping is needed! Is there another solution that is working (no JS!)?
|
<SfGrid TValue="Order" ID="Grid" @ref="portGrid" AllowSorting="true" AllowFiltering="true" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })">
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<GridPageSettings CurrentPage="@CurrentPage" PageSize="50"></GridPageSettings>
<GridEvents TValue="Order" DataBound="DataHandler"></GridEvents>
<GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" Width="140"></GridColumn>
</GridColumns>
</SfGrid>
@code {
public static List<Order> Orders { get; set; }
public SfGrid<Order> portGrid { get; set; }
public bool ContinuePaging = true;
public bool InitialRender { get; set; }
public double ID { get; set; } = 10;
public int CurrentPage { get; set; } = 5;
public async Task DataHandler()
{
if (ID != 0)
{
ID = 0;
await portGrid?.SelectRow(4);
}
} |
Unfortunately your proposal may not work - or just working with the same problem that the first adaptor call is to get the index of the page and row!
The content of the table can be changed after I have stored the page index! So its possible that the saved page index may be not correct anymore!
Or am I wrong?