How to remember group Expand/Collapse state on a data grid?

I have a data grid with multiple groupings. At the beginning all groups in collapse state. user will expand some nodes based on his requirement and I need to save that Expand/Collapse state. I'm saving grid state as DataGridSettings object. I can save groups using DataGridSettings.Groups but GroupDescriptor don't have any flag to store Expand/Collapse state.

How I can achieve this? Do I have to use custom object instead DataGridSettings?

DataGrid settings can save state for the entire grid only - saving state of items is not supported out-of-the-box.

Do you mind sharing how you get the initial groupings to collapse? I can't seem to get that to work correctly. I think my args.FirstRender is false which may be causing the problem. The AllGroupsExpanded option does work but I want the top group to be expanded and the 2nd group to be collapsed.

Thanks,
Wayne

Hi @wspray , You can try something like bellow...

protected void OnGroupRowRender(GroupRowRenderEventArgs args)
{
	if (args.FirstRender)
	{
		if (args.Group?.Level == 0)
		{
			args.Expanded = true;
		}
		else
		{
			args.Expanded = false;
		}
	}			
}

That is almost exactly what I have. The args.FirstRender is never being satisfied so the code is not executing.

void OnGroupRowRender(GroupRowRenderEventArgs args)
{
    if (args.FirstRender)
    {
        //string k = args.Group.Data.Key;
        //if (k.Contains("Week") == false)
        if (args.Group?.Level == 0)
        {
            args.Expanded = true;
        }
        else
        {
            args.Expanded = false;
        }
        //collapseGroup = false;
    }
}