All groups become collapsed after applying the filter.

I use the Excel filter.

WithEvents gdf As New GridExcelFilter

After I apply the filter, all my open groups become collapsed.

Is there a way to keep the original group state, after the filter is applied?

Should I also use Serialization/Deserialization to store and restore the group state?

Which event should I use to achieve this?

The gridexcelfilter has to events.



1 Reply

MG Mohanraj Gunasekaran Syncfusion Team November 13, 2017 12:02 PM UTC

Hi Burkhard, 

Thanks for using Syncfusion product. 

Yes, you can use serialization/deserialization to maintain the group state after filtering the records and this can be achieved by using RecordFilterItemChanging, RecordFilterItemChanged of GridExcelFilter and CategorizedRecords event. Please refer to the below code example, 

Code example 
Dim filter As New GridExcelFilter() 
AddHandler filter.RecordFiltersItemChanging, AddressOf filter_RecordFiltersItemChanging 
AddHandler filter.RecordFiltersItemChanged, AddressOf filter_RecordFiltersItemChanged 
AddHandler Me.gridGroupingControl1.CategorizedRecords, AddressOf gridGroupingControl1_CategorizedRecords 
 
Private IsRecordFilterItemChanged As Boolean = False 
Private Sub gridGroupingControl1_CategorizedRecords(ByVal sender As Object, ByVal e As Syncfusion.Grouping.TableEventArgs) 
            'Deserilize the GroupExpandState after complte the record filtering. 
    If IsRecordFilterItemChanged Then 
       DeserializeExpandState() 
       IsRecordFilterItemChanged = False 
    End If 
End Sub 
 
Private Sub filter_RecordFiltersItemChanged(ByVal sender As Object, ByVal e As Syncfusion.Collections.ListPropertyChangedEventArgs) 
            If e.Action = Syncfusion.Collections.ListPropertyChangedType.Add OrElse e.Action = Syncfusion.Collections.ListPropertyChangedType.Insert Then 
                IsRecordFilterItemChanged = True 
            End If 
End Sub 
 
Private Sub filter_RecordFiltersItemChanging(ByVal sender As Object, ByVal e As Syncfusion.Collections.ListPropertyChangedEventArgs) 
     If e.Action = Syncfusion.Collections.ListPropertyChangedType.Add OrElse e.Action = Syncfusion.Collections.ListPropertyChangedType.Insert Then 
         SerializeExpandState() 
     End If 
End Sub 
 
Private Sub SerializeExpandState() 
 
  'Serialize the expanded records before change the data source.  
  Dim groupExpandState As New List(Of GroupExpandState)() 
   For Each g As Syncfusion.Grouping.Group In Me.gridGroupingControl1.Table.TopLevelGroup.Groups 
        If g.IsExpanded Then 
           groupExpandState.Add(New GroupExpandState() With {.GroupIdentifier = g.UniqueGroupId(0).ToString(), .IsExpanded = g.IsExpanded}) 
        End If 
    Next g 
 
 Dim xw As New XmlTextWriter("GroupsExpandState.xml", System.Text.Encoding.UTF8) 
  Dim serializer As New XmlSerializer(GetType(List(Of GroupExpandState))) 
  serializer.Serialize(xw, groupExpandState) 
  xw.Close() 
End Sub 
 
Private Sub DeserializeExpandState() 
   'Deserialize the expanded records after changed the source. 
   Dim xr As XmlReader = New XmlTextReader("GroupsExpandState.xml") 
   Dim deserializer As New XmlSerializer(GetType(List(Of GroupExpandState))) 
   Dim expandState As List(Of GroupExpandState) = TryCast(deserializer.Deserialize(xr), List(Of GroupExpandState)) 
 
   For Each groupExpand As GroupExpandState In expandState 
        Dim groupIndex As Integer = Me.gridGroupingControl1.Table.TopLevelGroup.Groups.FindGroup(groupExpand.GroupIdentifier) 
        If groupIndex > -1 Then 
                    Me.gridGroupingControl1.Table.TopLevelGroup.Groups(groupIndex).IsExpanded = True 
        End If 
   Next groupExpand 
 
   Me.gridGroupingControl1.TableControl.Refresh() 
End Sub 
 
 
Sample link: GridGroupingControl 
 
Please let us know if you have any concerns. 
 
Regards, 
Mohanraj G 
 


Loader.
Up arrow icon