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.
Unfortunately, activation email could not send to your email. Please try again.

SfDataGrid Grouping with custom group template and dynamic collapsing?

Thread ID:

Created:

Updated:

Platform:

Replies:

129640 Mar 27,2017 07:38 AM Mar 28,2017 07:42 AM Xamarin.Forms 1
loading
Tags: SfDataGrid
Emil
Asked On March 27, 2017 07:38 AM

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;
        }

Vimal Prabhu Manohkaran [Syncfusion]
Replied On March 28, 2017 07:42 AM

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]); 
    } 
} 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;