Selection persistence not working in basic implementation

I've read through the documentation and the forums.  It was not difficult to get persistence for the grid filtering, sorting, paging.  However, just trying to enable the selection persistence upon navigation has never worked thus far.  Here is the code for our Grid which uses OData paging/filtering/sorting and all works great.  I have a button that navigates to another page based on the current selection.  When navigating back to the grid, the filter, page, sorting is all retained.  The selection, however, is not.

I've even attempted to write out the json from the Grid.GetPersistDataAsync and did not find anything related to the current selection.  So, I'm assuming there is an issue at the serialization stage.

I tried this with the latest version of 19.3 and now 19.4.

<div class="row">
    <SfButton Content="Navigate" OnClick="Navigate" />
</div>
<div class="row">
    <SfGrid @ref="Grid" TValue="ResponseType" AllowPaging="true" AllowSorting="true" AllowFiltering="true" AllowSelection="true"
            EnablePersistence="true" ID="Roots">
        <SfDataManager Url="queryroot" Adaptor="Adaptors.ODataV4Adaptor"/>
        <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Menu"/>
        <GridPageSettings PageCount="10" PageSize="18" PageSizes="true"/>
        <GridSelectionSettings PersistSelection="true" />
        <GridColumns>
            <GridColumn Field=@nameof(ResponseType.Id) Visible="false" IsPrimaryKey="true" />
            <GridColumn Field=@nameof(ResponseType.Name) HeaderText="Name" />
            <GridColumn Field=@nameof(ResponseType.InputDate) HeaderText="Input Date" Format="d" Type="ColumnType.Date" />
            <GridColumn Field=@nameof(ResponseType.Number) HeaderText="Number" />
            <GridColumn Field=@nameof(ResponseType.Currency) HeaderText="Currency" />
            <GridColumn Field=@nameof(ResponseType.CreatedUtc) HeaderText="Created" Type="ColumnType.DateTime">
                <Template>
                    @{
                        <div>@((context as ResponseType).CreatedUtc.UtcToLocalTime())</div>
                    }
                </Template>
            </GridColumn>
            <GridColumn Field=@nameof(ResponseType.UpdatedUtc) HeaderText="Updated" Type="ColumnType.DateTime">
                <Template>
                    @{
                        <div>@((context as ResponseType).UpdatedUtc.UtcToLocalTime())</div>
                    }
                </Template>
            </GridColumn>
        </GridColumns>
    </SfGrid>
</div>

@code {
    SfGrid<ResponseType> Grid;
    protected async Task Navigate()
    {
        var json = await Grid.GetPersistDataAsync();
        Console.WriteLine(json);

        var selectedRecords = await Grid.GetSelectedRecordsAsync();
        if (selectedRecords.Count > 0)
            NavigationManager.NavigateTo($"/root/{selectedRecords[0].Id}");
    }
}

3 Replies

RN Rahul Narayanasamy Syncfusion Team March 10, 2022 01:43 PM UTC

Hi Jeff, 

Greetings from Syncfusion. 

Query: Selection persistence not working in basic implementation - I have a button that navigates to another page based on the current selection.  When navigating back to the grid, the filter, page, sorting is all retained.  The selection, however, is not. 

We will let you know that the GridSelectionSettings state was not persisted while using EnablePersistence feature. The following properties only saved and loaded into the Grid.  

  • Columns
  • GridFilterSettings
  • GridSortSettings
  • GridGroupSettings
  • GridPageSettings

Reference

Please let us know if you have any concerns. 

Regards, 
Rahul 



JV Jeff Voigt March 10, 2022 06:51 PM UTC

OK.  Then what's the point of setting the <GridSelectionSettings PersistSelection="true">?  Are you telling the community that the feature is not available, and we will have to do it ourselves?  That's fine but I want to be sure that is what you are saying.



RN Rahul Narayanasamy Syncfusion Team March 11, 2022 01:01 PM UTC

Hi Jeff, 

Thanks for the update. 

Query: Then what's the point of setting the <GridSelectionSettings PersistSelection="true">? 

The PersistSelection in GridSelectionSettings is used to persist the Grid row selecting while performing data operation like filtering, sorting, paging etc. But It will not persist the Grid row selection while navigating another page using browser page navigation(NavigationManager.NavigateTo)

Also as we said in the previous update, the GridSelectionSettings was not persisted while using EnablePersistence feature. 

Please let us know if you have any concerns. 

Regards, 
Rahul 


Loader.
Up arrow icon