AggregateColumn show/hide when Allowgrouping is true or false

Hi
I have this grid that depending on whether it is grouped or not, it appears like this below.


NO GROUP


GROUPING




I would like when is not grouping appear normal but when is grouping show aggregateColum.

Thanks


1 Reply 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team June 17, 2021 05:05 AM UTC

Hi Ainhoa,  
 
Greetings from Syncfusion support.  
 
Query: “I would like when is not grouping appear normal but when is grouping show aggregateColum. 
 
We have analyzed your query and we understand that you have rendered the DetailTemplate Grid where grouping is enabled based on RadioButtons. We suspect that you want to display the GroupCaption (highlighted as red in screenshot) at all times when Grid is not Grouped. GroupCaption will be displayed only when column is grouped and it is different from AggregateColumn. We do not have direct support to achieve your requirement.  
 
Since you have used DetailTemplate Grid, there must be some relation (any column) between parent and detail grid. So we have used that column to Group and displayed an normal empty groupcaption. In the below code example, we have used EmployeeID column as related between Parent and Detail Grid and also for grouping. When no Grouping is enabled.  
 
Refer the below code example 
 
<SfRadioButton Label="Group" TChecked="string" Name="options" @bind-Checked="stringChecked" Value="Group"  ValueChange="@((args)=>OnChange(args,"Group"))"></SfRadioButton> 
<SfRadioButton Label="No" TChecked="string" Name="options" @bind-Checked="stringChecked" Value="No" ValueChange="@((args)=>OnChange(args,"No"))"></SfRadioButton> 
  
  
<SfGrid @ref="Grid" DataSource="@Employees" AllowGrouping="true" Height="315px"> 
    <GridGroupSettings Columns="@cols" ShowDropArea="false"> 
        <CaptionTemplate> 
            @{ 
                var order = (context as CaptionTemplateContext); 
                <div>@GetData(order)</div> 
            } 
        </CaptionTemplate> 
    </GridGroupSettings> 
    <GridTemplates> 
        <DetailTemplate> 
            @{ 
                var employee = (context as EmployeeData); 
                <SfGrid DataSource="@Orders" Query="@(new Query().Where("EmployeeID""equal", employee.EmployeeID))"> 
                    <GridColumns> 
                        <GridColumn Field=@nameof(Order.OrderID) HeaderText="First Name" Width="110"> </GridColumn> 
                        <GridColumn Field=@nameof(Order.CustomerName) HeaderText="Last Name" Width="110"></GridColumn> 
                        <GridColumn Field=@nameof(Order.ShipCountry) HeaderText="Title" Width="110"></GridColumn> 
                    </GridColumns> 
                </SfGrid> 
            } 
        </DetailTemplate> 
    </GridTemplates> 
    <GridColumns> 
        <GridColumn Field=@nameof(EmployeeData.FirstName) HeaderText="First Name" Width="110"> </GridColumn> 
        <GridColumn Field=@nameof(EmployeeData.LastName) HeaderText="Last Name" Width="110"></GridColumn> 
        <GridColumn Field=@nameof(EmployeeData.EmployeeID) HeaderText="Title" Width="110"></GridColumn> 
        <GridColumn Field=@nameof(EmployeeData.Title) HeaderText="Title" Width="110"></GridColumn> 
        <GridColumn Field=@nameof(EmployeeData.Country) HeaderText="Country" Width="110"></GridColumn> 
    </GridColumns> 
</SfGrid> 
  
@code{ 
    public SfGrid<EmployeeData> Grid { getset; } 
    public string[] cols { getset; } = new string[] { "EmployeeID" }; 
    private string stringChecked = "No"; 
    public void OnChange(ChangeArgs<string> Args, string val) 
    { 
        if(val == "Group") 
        { 
            cols = new string[] { "Title" }; 
        } 
        else if(val == "No") 
        { 
            cols = new string[] { "EmployeeID" }; 
        } 
    } 
    public string GetData(CaptionTemplateContext args) 
    { 
        if (args.Field == nameof(EmployeeData.EmployeeID)) 
        { 
            return ""; 
        } 
        else 
        { 
            return $"{args.Field} : {args.Key} - {args.Count.ToString()} items"; 
        } 
    } 
 
 
Kindly refer the below sample for your reference 
 
 
Refer our UG documentation for your reference 
 
 
Please get back to us if you have further queries or if we misunderstood your queries.    
 
Regards, 
Vignesh Natarajan. 


Marked as answer
Loader.
Up arrow icon