We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SfDataGrid Grouping with custom group template and dynamic collapsing?

I have 2 questions regarding grouping

1)  is it possible to have custom template as group header? I would like to add a switch in all groups if possible.
2) Based on a a boolean column I want group to be collapsed or not collapsed when page is loaded. I tried as below all collapsed by default

    this.datagrid.GroupCollapsing += dataGrid_GroupCollapsing;
   AllowGroupExpandCollapse="True"
  AutoExpandGroups="False"

then control it within GroupCollapsing event but this is event is not called by AllowGroupExpandCollapse, It is only called when I collapse manually myself by tapping on a group. How can I achieve it? Best is if possible with binding in mvvm.

    void dataGrid_GroupCollapsing(object sender, Syncfusion.SfDataGrid.XForms.GroupChangingEventArgs e)
        {
            var Items= (e.OriginalSender as SfDataGrid).BindingContext as List<Item>;
            if (!Items[((int)e.Group.Key)-1].IsCompleted)
                e.Cancel = true;
        }

1 Reply

VP Vimal Prabhu Manohkaran Syncfusion Team March 28, 2017 11:42 AM UTC

Hi Emil,

Thanks for contacting Syncfusion support. Regarding your query of GroupHeaderTemplate, we have already added this to our feature request list and you can expect the feature to be available in any of our upcoming releases post 2017 Volume 2 Main Release (tentative).

Regarding your query of expanding/collapsing a group based on a bool value, we have prepared a simple sample where we have made use of the GridLoaded event to achieve your requirement. Please refer the below code snippet. In this sample we have collapsed a group if the first record of that group has its bool value as true. As requested we have made use of the behaviors concept to achieve this requirement in MVVM.

 
private void DataGrid_GridLoaded(object sender, GridLoadedEventArgs e) 
{ 
    SfDataGrid dataGrid = (sender as SfDataGrid); 
    for (int i = 0; i < dataGrid.View.Groups.Count; i++) 
    { 
        bool canCollapse = ((dataGrid.View.Groups[i] as Group).Records[0].Data as OrderInfo).IsClosed; 
        if (canCollapse) 
            dataGrid.CollapseGroup((Group)dataGrid.View.Groups[i]); 
        else 
            dataGrid.ExpandGroup((Group)dataGrid.View.Groups[i]); 
    } 
} 


Loader.
Live Chat Icon For mobile
Up arrow icon