Store Status (Groups Collapes/Expanded/SelectedRow) > Load data > Restore previous Status

Everytime I load new information into the GCC, all the previously expanded groups become collapes and the selected record is the first record.

Before I load new data into the souce data table, I want to store the current record position and the status of each group (expanded/collapsed).

Then I load the data.

Then I need to restore the status of each group, immediately and set the selected row automatically.

Is there a easy-peasy way to achieve thisssssssssszzzzzzzzzzzzz..............?? :-)

1 Reply

AR Arulpriya Ramalingam Syncfusion Team November 9, 2017 12:03 PM UTC

Hi Burkhard,   
  
Thanks for your interest in Syncfusion products.   
  
We could understand your requirement and created a simple sample as per your requirement. From your update, we suspect that you want to save the Expand/Collapse status of each record/group and current record position, and reuse it after refreshed the grid. The GridGroupingControl does not have the direct support to save the Expand status of a group/record, current record and current record position. This can be achieved by serializing/deserializing a list which holds the Expand status of the group/record and current record position. Please refer to the below code example to serialize/deserialize the Expand/Collapse status of the records and position of the current record,   
  
Code example:   
private void Serialization_Click(object sender, EventArgs e)   
{   
    List<RecordExpandState> recordExpandState = new List<RecordExpandState>();   
    List<RecordSelectionState> recordSelectionState = new List<RecordSelectionState>();   
    foreach (Record record in this.gridGroupingControl1.Table.Records)   
    {   
        {   
            //To save the expanded records   
            recordExpandState.Add(new RecordExpandState() { recordIndex =this.gridGroupingControl1.Table.Records.IndexOf(record), IsExpanded = record.IsExpanded });   
        }   
    }   
    //To save the current record position   
    recordExpandState.Add(newRecordExpandState(this.gridGroupingControl1.Table.Records.IndexOf(this.gridGroupingControl1.Table.CurrentRecord)));   
    XmlTextWriter xmlWriter = new XmlTextWriter("RecordsExpandState.xml"Encoding.UTF8);   
    XmlSerializer serializer = new XmlSerializer(typeof(List<RecordExpandState>));   
    serializer.Serialize(xmlWriter, recordExpandState);   
    xmlWriter.Close();   
   
    XmlTextWriter xw1 = new XmlTextWriter("RecordSelectionState.xml"Encoding.UTF8);   
   
}   
   
private void Deserialization_Click(object sender, EventArgs e)   
{   
    XmlReader xmlReader = new XmlTextReader("RecordsExpandState.xml");   
    XmlSerializer serializer = new XmlSerializer(typeof(List<RecordExpandState>));   
    List<RecordExpandState> expandState = serializer.Deserialize(xmlReader) as List<RecordExpandState>;   
    foreach (RecordExpandState recordExpandState in expandState)   
    {   
        //To retrieve the expanded records   
        this.gridGroupingControl1.Table.Records[recordExpandState.recordIndex].IsExpanded = recordExpandState.IsExpanded;   
        //To set the saved current record as current record after modifying the data source   
        this.gridGroupingControl1.Table.Records[recordExpandState.currentRecordIndex].SetCurrent();   
    }   
}   
   
  
Here we have provided two samples for serializing the record and group states.   
If you want to serialize/deserialize the ParentChild hierarchy (i.e., no groups are added in your application), please make use of below sample,     
  
Sample link: RecordSerialization    
   
If you want to serialize the group states that are added to the TopLevelGroupOptions, please refer to the below sample,   
  
Sample link: GroupStateSerialization   
  
   
Please let us know if you have any other concerns.   
  
Regards,   
Arulpriya  


Loader.
Up arrow icon