Hi,
We use a grid with a custom data adaptor.
If a user select a row in our grid and we call a rebind in our end to show updated data in the grid the selection is lost! Is there a way to keep the selection in some way?
We define our data adaptor in the front code:
<SfDataManager Adaptor="Adaptors.CustomAdaptor">
<HQDataAdaptorComponentRedux
SourceData="@ReduxStoreData"
TSource="TSourceEntity"
TTarget="TTargetEntity"
DisableDefaultHQSorting="@DisableDefaultHQSorting">
</HQDataAdaptorComponentRedux>
</SfDataManager>
And the parameter
AllowSelection="true"
is enabled as well.
I attached a screen cast!
Best regards
Sven
Hi Sven,
Greetings from Syncfusion support.
We have checked your query and prepared an simple sample as per your reference. Here we have used RowSelectHandler to get the selected row data and stored the index in the local variable and after performing external edit by using SelectRowAsync method we have performed selection programmatically in the DataGrid. Kindly refer the attached code snippet and sample for your reference.
|
<SfGrid DataSource="@GridData" @ref="Grid" AllowPaging="true"> <GridEvents RowSelected="RowSelectHandler" RowDeselected="RowDeSelectHandler" TValue="OrderDetails"></GridEvents> <GridColumns>
… </GridColumns> </SfGrid> </div> </div> </div> @code{ public double index; public bool CanSelect = true; public void RowSelectHandler(RowSelectEventArgs<OrderDetails> args) { if (CanSelect) {
index = args.RowIndex; } } public async Task Save() { CanSelect = false; await Grid.SelectRowAsync(index); CanSelect = true; } } |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp1804632568.zip
Kindly get back to us if you have further queries.
Regards,
Monisha
Alright, thank you.
Exists a way to get the index of any entity if I only have the id or another property of the entity of my data source?
This would be great, because then I could select the row after a reload again!
Thank you
Sven
Hi Sven,
Thanks for the update.
We have checked your query and we suspect that you need to get the index of the selected column. So we would like to inform that you can get index by using GetRowIndexByPrimaryKeyAsync method of DataGrid. Kindly refer the attached code snippet and UG for your reference.
|
public async Task RowSelect(RowSelectingEventArgs<Order> args)
{ var index = await Grid.GetRowIndexByPrimaryKey(args.Data.OrderID);
}
|
Kindly get back to us if you have further queries.
Regards,
Monisha
Perfect. Thank you
Hi Sven,
Welcome.
We are glad to hear that your query has been resolved. So we are proceeding to mark this ticket as closed. Kindly get back to us if you have further queries. As always we will be happy to help you.
Regards,
Monisha