Keep selected row after rebind

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


Attachment: Screen_Recording_20220519_at_14.02.40.mov_300bab8c.zip

5 Replies

MS Monisha Saravanan Syncfusion Team May 20, 2022 12:43 PM UTC

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


Reference: https://blazor.syncfusion.com/documentation/datagrid/selection#perform-toggle-selection-programmatically

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SelectRowAsync_System_Double_System_Nullable_System_Boolean__


Kindly get back to us if you have further queries.


Regards,

Monisha



SB Sven Boris Bornemann June 1, 2022 07:19 AM UTC

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



MS Monisha Saravanan Syncfusion Team June 2, 2022 02:35 PM UTC

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);

 

    }

 



Reference: https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_GetRowIndexByPrimaryKeyAsync_System_Object_


Kindly get back to us if you have further queries.


Regards,

Monisha



SB Sven Boris Bornemann June 7, 2022 07:48 AM UTC

Perfect. Thank you



MS Monisha Saravanan Syncfusion Team June 8, 2022 06:26 AM UTC

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


Loader.
Up arrow icon