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}");
}
}
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.