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

how to get tablesummry row

Sir/Madam, 

I am using SFDatagrid. I have added tablesummary row using following code:

GridTableSummaryRow summaryRow = new GridTableSummaryRow

{

    ShowSummaryInRow = false,

    Title = "Total",

    Position = Position.Bottom

};

foreach (string Fld in GridTotalFld)

{

    summaryRow.SummaryColumns.Add(new GridSummaryColumn()

    {

        Name = Fld,

         MappingName = Fld,

         Format = "{Sum}",

         SummaryType = SummaryType.DoubleAggregate

  });

}

dataGrid.TableSummaryRows.Add(summaryRow);

dataGrid.LiveDataUpdateMode = LiveDataUpdateMode.AllowSummaryUpdate;


Now I want to get total of all columns in Array or any Json format or let me know how to get TableSummary row object so I can get the total of each column like dataRowView.Row[FldName].

 

Thanking you.




3 Replies

SV Suja Venkatesan Syncfusion Team November 22, 2022 10:15 AM

Hi Amish,


Regarding “Get GridTableSummaryRow


You can directly access the GridTableSummaryRow from GridTableSummaryRows collection of SfDataGrid as like below code snippet.


Code Snippet:

foreach(var summary in dataGrid.TableSummaryRows)

{

  GridSummaryRow sum = summary as GridTableSummaryRow;

  for (int i=0; i< sum.SummaryColumns.Count;i++)

  {

    var col = sum.SummaryColumns[i];


Please let us know if you need any further assistance.


Regards,

Suja



AM Amish replied to Suja Venkatesan November 22, 2022 11:37 AM

But how can I get the value of the column of the tablesummary Row?

Please check attached image herewith. I want the marked squared value from tablesummary row for Qty and Amout column.



Attachment: TotalSummaryRow_ff265782.zip


SV Suja Venkatesan Syncfusion Team November 23, 2022 10:14 AM

You can access the GridTableSummaryRow and get the value of it using GetSummaryDisplayText method as like below code snippet.


Code Snippet:

        private void Button_Clicked(object sender, EventArgs e)

        {

           var a= dataGrid.View.SummaryRows;

            foreach (var row in dataGrid.GetVisualContainer().RowGenerator.Items)

            {

                if(row is SpannedDataRow)

                {

                    var spanneddatarow = (row as SpannedDataRow);

                    if(spanneddatarow.RowType==RowType.TableSummaryRow)

                    {

                      var summaryRecordEntry= ((spanneddatarow.RowData) as SummaryRecordEntry);

                        foreach (var col in summaryRecordEntry.SummaryRow.SummaryColumns)

                        {

                           var colname= col.MappingName;

                            //get the value of every summarycolumn of summaryrow

                           var val = SummaryCreator.GetSummaryDisplayText(summaryRecordEntry,colname, dataGrid.View);

                        }

                    }

 

                }

            }

        }


Please refer the below reference regarding GetSummaryDisplayText.

Reference link: https://help.syncfusion.com/cr/xamarin/Syncfusion.Data.SummaryCreator.html#Syncfusion_Data_SummaryCreator_GetSummaryDisplayText_Syncfusion_Data_SummaryRecordEntry_System_String_Syncfusion_Data_ICollectionViewAdv_


We have attached a simple sample based on your requirement. You can customize the sample as per your wish. Please let us know if you need any further assistance.


Regards,

Suja


Attachment: DataGridXamarin_8f3302aa.zip

Loader.
Live Chat Icon For mobile
Up arrow icon