I am unable to persist Expanded State of Rows when Page is refreshed
<SfTreeGrid ID="TreeGridID" EnablePersistence="true" DataSource="@HierarchyDetatillist" @ref="HierarchyTreeGrid" IdMapping="CatId" ParentIdMapping="ParentId" TreeColumnIndex="0"
EnableCollapseAll="true" Toolbar="@(new List<string>() { "Search" })" AllowPaging="false" RowHeight="40" AllowFiltering="true" AllowSorting="false">
<TreeGridFilterSettings HierarchyMode="FilterHierarchyMode.None" Type="Syncfusion.Blazor.TreeGrid.FilterType.Excel"> </TreeGridFilterSettings>
<TreeGridEvents QueryCellInfo="OnQueryCellInfo" TValue="CategoryHierarchy"></TreeGridEvents>
<TreeGridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></TreeGridSelectionSettings>
This is my initial Grid Setting
Can i have a sample or little guidance related to this kindly. I am stuck on this issue
How can we achieve this requirement, any work around if possible
|
<SfTreeGrid ID="TreeGrod" DataSource="@TreeData" @ref="TreeGrid" IdMapping="TaskId" ParentIdMapping="ParentId" TreeColumnIndex="1" EnablePersistence="true">
<TreeGridEvents Collapsed="collapsed" DataBound="databound" TValue="BusinessObject"></TreeGridEvents>
<TreeGridColumns>
<TreeGridColumn Field="TaskId" HeaderText="Task ID" Width="80" IsPrimaryKey="true" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Right"></TreeGridColumn>
….
</TreeGridColumns>
</SfTreeGrid>
@code{
public SfTreeGrid<BusinessObject> TreeGrid;
public int[] currentdata = new int[] {};
List<int> list = new List<int>();
public class BusinessObject
{
public int TaskId { get; set; }
public string TaskName { get; set; }
public int Duration { get; set; }
public int Progress { get; set; }
public string Priority { get; set; }
public int? ParentId { get; set; }
}
public List<BusinessObject> TreeData = new List<BusinessObject>();
public async void databound(object args)
{
if (TreeGrid != null && localStorage != null){
//checking whether it has localstorage
currentdata =(await localStorage.GetItemAsync<int>("currentdata"));
//retriving collapsed key value in local storage using getItem method
if (currentdata != null) {
for (var i = 0; i < currentdata.Length; i++)
{
TreeGrid.CollapseByKeyAsync(currentdata[i]); //collapsing row using collapseByKey method
}
}
}
}
public void collapsed(RowCollapsedEventArgs<BusinessObject> args)
{
if (args.Data != null)
{
list.Add(args.Data.TaskId);
currentdata =list.ToArray();; //Get the collapsed row primary key value
localStorage.SetItemAsync("currentdata", currentdata);
}//store the collapsed row primary key value
} |