How to update SfDataGrid when binding value to AutoExpandGroups property changes
Hello,
I am working on a SfDataGrid where I have a ViewModel value binding to the AutoExpandGroups. Although the value binding changes, the SfDataGrid does not refresh/update AutoExpandGroups to have the columns either expand or collapse.
Are you able to provide an example in which you have a SfDataGrid's AutoExpandGroups property in xaml binded to a ViewModel property and the grid updates when the ViewModel property changes?
Hi Eric Nguyen,
We have investigated the reported scenario. We suspect that the reported problem may occur due to the AutoExpandGroups property value being updated in a different DataContext.
However, your requirement to update the AutoExpandGroups property via binding from a ViewModel property can be achieved by binding the AutoExpandGroups property and changing the value in the same DataContext.
Code snippet related to binding the AutoExpandGroups property:
|
<syncfusion:SfDataGrid Name="sfDatagrid" ItemsSource="{Binding Orders}" GroupDropAreaText="Drag and drop the columns here" ShowGroupDropArea="True" AutoGenerateColumns="True" AllowGrouping="True" AllowEditing="True" AutoExpandGroups="{Binding IsGroupsExpanded}"> </syncfusion:SfDataGrid> <Button Grid.Row="1" Width="100" Height="30" Click="OnExpandCollapseGroups" Content="Expand/Collapse"/> |
Code snippet related to update ViewModel property:
|
private void OnExpandCollapseGroups(object sender, RoutedEventArgs e) { var viewModel = (ViewModel)this.DataContext; viewModel.IsGroupsExpanded = !viewModel.IsGroupsExpanded; } |
Find a sample demo in the attachment.
Note: If the AutoExpandGroups property is enabled and you make grouping in SfDataGrid, all groups will be expanded. In case you group records first and then enable the property, it will not affect the existing groups. However, To see the effect, you need to reapply the grouping after updating the property. You need to ensure that the property is enabled before grouping in SfDataGrid.
Please let us know if you have any concerns on this.
Regards,
Rabina M
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Attachment: SfDataGrid_AutoExpandGroups_e384b6a5.zip
Hello,
The AutoExpandGroups property is being updated in the same DataContext but to refresh and rebuild the grid, my method is through resetting the item source to refresh existing groups. Is there a better way to accomplish this without having to reset the items source binding to a new Observable Collection? It does not seem like there is a method that can refresh grid with the existing data without setting it to a new observable collection.
When I update the AutoExpandGroups property binding, I want the SfDataGrid to reflect that property change without having to rebuild the SfDataGrid.
Best,
Eric Nguyen
Eric Nguyen,
We have investigated the reported scenario and would like to clarify the behavior of the AutoExpandGroups property in SfDataGrid. This property is used to automatically expand all groups at the time of grouping, based on its current value.
Please note that changing the value of AutoExpandGroups after grouping has already occurred will not affect the existing groups. This is the expected behavior and is working as designed.
We appreciate your understanding and cooperation.
Please let us know if you need any further assistance.
Is there a way to have the grid refresh without resetting the item source? It is not ideal to refresh the item source every time another bound property is changed, it requires the violation of design patterns to put that type of logic into a view model (i.e. binding target of the SfDataGrid.)
Thomas Killory,
We have investigated the reported scenario. As previously mentioned, the AutoExpandGroups property does not reflect changes when modified at runtime. However, you can expand or collapse all the groups at programmatically at runtime by using SfDataGrid.ExpandAllGroup and SfDataGrid.CollapseAllGroup methods.
Refer to the following user guide documentation for more details on ExpandAllGroup and CollapseAllGroup:
UG Link: Expand or collapse all the Groups
- 5 Replies
- 3 Participants
- Marked answer
-
EN Eric Nguyen
- Jun 27, 2025 02:51 PM UTC
- Aug 21, 2025 12:50 PM UTC