How to prevent cell merging for group rows (grouped grid Excel export)?

Hello,

When I export grouped grid to Excel (using standard Grid.ExportToExcelAsync() method), I get grouped rows merged. I have GroupCaptionTemplate set up for these column and the fact that they are merged prevents from seeing actual subtotals.

Image_4668_1738865716280

When I unmerge cells manually, subtotals become visible.

How can I prevent merging these cells when exporting?

Image_6464_1738865846979

Thank you in advance.


5 Replies 1 reply marked as answer

AS Atchaya Sekar Syncfusion Team February 10, 2025 01:43 PM UTC

Hi Vasyl,

 

We request you to share the issue reproducing sample or input files for further investigation. This will help us proceed further and provide assistance.

 

Regards,

Atchaya S.



VS Vasyl Shepelyov February 11, 2025 09:08 AM UTC

Hello,

Please find attached solution which reproduces the issue. Please update "RegisterLicense()" in Program.cs before using it.


You can find the example here:

Image_9145_1739264882279


Best regards,

Vasyl


Attachment: GroupedGridExcelExport_eee763a0.zip



NP Naveen Palanivel Syncfusion Team February 16, 2025 05:56 PM UTC

Hi Vasyl,


We have reviewed your query and the provided sample. It appears that the reported issue occurs when more than half of the column aggregates are defined like a custom component, while some column aggregates are defined directly in the Home.razor page (not like a component). To resolve this issue, we recommend defining all aggregates consistently, either by defining each column's aggregate directly in the Home.razor page or by using a custom component for all column aggregates. Additionally, please share the details of why you are defining aggregates in this way or specify your exact requirement and what you are trying to achieve. Please refer to the modified sample and code snippet for more information.


@page "/gridPage"

 

</GridGroupSettings>

<GridAggregates>

     <GridAggregate>

         <GridAggregateColumns>

 

            

             <ShPrAggrSumComponent ColumnName="@nameof(ShRec.TotalSales)" NumberFormat="@Const.NumberFormatN2"></ShPrAggrSumComponent>

             <ShPrAggrSumComponent ColumnName="@nameof(ShRec.Cogs)" NumberFormat="@Const.NumberFormatN2"></ShPrAggrSumComponent>

             <ShPrAggrSumComponent ColumnName="@nameof(ShRec.UnitCost)" NumberFormat="@Const.NumberFormatN2"></ShPrAggrSumComponent>

             <ShPrAggrSumComponent ColumnName="@nameof(ShRec.Profit)" NumberFormat="@Const.NumberFormatN2"></ShPrAggrSumComponent>

             <AggrCustomComponent ColumnName="@nameof(ShRec.GrossMargin)" Result="@_result"></AggrCustomComponent>

             <AggrCustomComponent ColumnName="@nameof(ShRec.ProfitMargin)" Result="@_result"></AggrCustomComponent>

 

         </GridAggregateColumns>

     </GridAggregate>

</GridAggregates>

<GridColumns>

 

AggrCustomComponent.razor

 

@using Syncfusion.Blazor.Grids

@using GroupedGridExcelExport.Data

 

<GridAggregateColumn Field=@ColumnName Type="AggregateType.Custom">

    <GroupCaptionTemplate>

        @{

            var aggregate = context as AggregateTemplateContext;

            if (ColumnName == "GrossMargin")

            {

                <span><small class="nowrap-custom">@GetGrossMarginAggregate(aggregate!.Key)</small></span>

            }

          else{

                <span><small class="nowrap-custom">@GetProfitMarginAggregate(aggregate!.Key)</small></span>

          }

 

           

        }

    </GroupCaptionTemplate>

    <FooterTemplate>

        @{

            var aggregate = context as AggregateTemplateContext;

            var test = aggregate;

            if (ColumnName == "GrossMargin"){

                <span><small class="nowrap-custom">@GetGrossMarginAggregate(aggregate!.Key)</small></span>

            }

            else{

                <span><small class="nowrap-custom">@GetProfitMarginAggregate(aggregate!.Key)</small></span>

            }

          

 

         

        }

    </FooterTemplate>

</GridAggregateColumn>

 

@code {

    [Parameter]

    [EditorRequired]

    public string ColumnName { get; set; } = null!;

 

    [Parameter]

    [EditorRequired]

    public List<ShRec>? Result { get; set; }

 

 

 

    public string GetGrossMarginAggregate(string? orderNumber)

    {

        if (Result != null)

        {

            var rec = ShRec.Aggregate(Result.Where(r => string.IsNullOrWhiteSpace(orderNumber) || r.OrderNumber == orderNumber));

            return rec.GrossMarginFunc(rec)?.ToString(Const.PercentageFormatN1) ?? "0.0%";

        }

        else

            return "0.0%";

    }

    public string GetProfitMarginAggregate(string? orderNumber)

    {

        if (Result != null)

        {

            var rec = ShRec.Aggregate(Result.Where(r => string.IsNullOrWhiteSpace(orderNumber) || r.OrderNumber == orderNumber));

            return rec.ProfitMarginFunc(rec)?.ToString(Const.PercentageFormatN1) ?? "0.0%";

        }

        else

           return "0.0%";

    }

  

}

 


Regards,

Naveen.


Attachment: GroupedGridExcelExport_5a0a1837.zip

Marked as answer

VS Vasyl Shepelyov February 17, 2025 09:43 AM UTC

Hi Naveen,

Thank you for your reply, that's an interesting observation.

I moved the remaining 2 columns to a separate component and it solved the problem, cell merging doesn't affect the columns with subtotals any more.

There was no specific reason to design it like this, I had 15 columns with "Sum" function and 2 columns with custom subtotal function, so I just moved these 15 to a separate component. But no issue to have the remaining 2 columns in another component.

Best regards,

Vasyl



NP Naveen Palanivel Syncfusion Team February 18, 2025 11:56 AM UTC

Hi Vasyl,

Thanks for the update

We are glad to hear that the reported response was helpful at your end. Kindly get back to us if you have further queries. As always we will be assist you.


Thanks,

Naveen


Loader.
Up arrow icon