How to define TableSummary for SfDataGrid with autogenerated columns only?

Snippet

When I know the name of column (MyName) it is working when defined like this:


<syncfusion:SfDataGrid.TableSummaryRows>      <syncfusion:GridTableSummaryRow Position="Top" ShowSummaryInRow="False">            <syncfusion:GridTableSummaryRow.SummaryColumns>                 <syncfusion:GridSummaryColumn                            Name="CountIssues"                            Format="'{Count:d}(Count)'"                            MappingName="MyName"                        SummaryType="CountAggregate" />                     </syncfusion:GridTableSummaryRow.SummaryColumns>       </syncfusion:GridTableSummaryRow>  </syncfusion:SfDataGrid.TableSummaryRows>

How do I have to define when I use the grid with autogenerated columns only? I do not know the name of the columns before. Is it possible to bind to the first column always?

3 Replies 1 reply marked as answer

AR Arulpriya Ramalingam Syncfusion Team September 16, 2021 01:35 PM UTC

Hi Karl, 
 
Thank you for your interest in Syncfusion products. 
 
In order to add TableSummary for the first column when AutoGeneratingColumns is enabled, the summaries can be added in AutoGeneratingColumn event of SfDataGrid which triggers for each columns when the columns are generated. Please make use of the below code example for further reference. 
 
Example code 
 
//Event subscription 
dataGrid.AutoGeneratingColumn += dataGrid_AutoGeneratingColumn; 
 
bool isFirstColumn = true; 
//Event customization 
private void dataGrid_AutoGeneratingColumn(object sender, Syncfusion.UI.Xaml.Grid.AutoGeneratingColumnArgs e) 
{ 
    if (isFirstColumn) 
    { 
        isFirstColumn = false; 
        this.dataGrid.TableSummaryRows.Add(new GridTableSummaryRow() 
        { 
            ShowSummaryInRow = false, 
            SummaryColumns = new ObservableCollection<ISummaryColumn>() 
            { 
                new GridSummaryColumn() 
                { 
                    Name = "Sum", 
                    MappingName=e.Column.MappingName, 
                    SummaryType= SummaryType.Int32Aggregate, 
                    Format="Total UnitPrice : {Sum:c}" 
                } 
            } 
        }); 
 
    } 
} 
 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Arulpriya R. 



KW Karl-Heinz Wenzel replied to Arulpriya Ramalingam September 30, 2021 01:13 PM UTC

Thank you.

This is working so far. 

As I'm going to load different collections into the grid, I'm wondering what would be the best event to reset  isFirstColumn to true again? 

ItemsSourceChanged seems to fit. Would you recommend another event?






VS Vijayarasan Sivanandham Syncfusion Team October 1, 2021 10:12 AM UTC

Hi Karl-Heinz Wenzel

Thanks for the update.

As you mentioned in the update ItemsSourceChanged is the proper event to reset isFirstColumn to true again while loading different collections into the SfDataGrid. Please let us know if you require any other assistance from us.

Regards,
Vijayarasan S


Marked as answer
Loader.
Up arrow icon