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

GridSummaryRowDescriptor if Event for clicking on the column

Hello,

Currently i have a GGC and i have a _ClickCell event on that grid.

 I use this event to see
 if the user has clicked on any column  in one specific column and perform some actions based on that.

I need it to dynamically add a summary row (GridSummaryRowDescriptor) for that column
with the sum (if it is a number) in the clicked column


Thanks in advance,

7 Replies

AA Arulraj A Syncfusion Team November 21, 2018 09:27 AM UTC

Hi Gregory, 

Thanks for using Syncfusion product. 

To add the summary while click on the column, you could use the GridTableCellStyleInfo and SummaryRows in TableControlCellClick event. Please refer the following code example, 

Code example 
this.gridGroupingControl1.TableControlCellClick += GridGroupingControl1_TableControlCellClick; 
 
private void GridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e) 
{ 
    if (e.TableControl.CurrentCell.MoveFromColIndex == e.TableControl.CurrentCell.ColIndex) 
        return; 
 
    GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); 
    if (style.CellValueType == typeof(int)) 
    { 
        if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null) 
        { 
            string columnName = style.TableCellIdentity.Column.Name; 
            if (this.gridGroupingControl1.TableDescriptor.SummaryRows.Count > 0) 
                //Clear the previous summary rows to add the  
                this.gridGroupingControl1.TableDescriptor.SummaryRows.Clear(); 
 
            GridSummaryColumnDescriptor scd = new GridSummaryColumnDescriptor(); 
            scd.SummaryType = Syncfusion.Grouping.SummaryType.Int32Aggregate; 
            scd.Format = "{Sum}"; 
            scd.DataMember = columnName; 
            scd.Name = "SumOf" + columnName; 
 
            GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor("Row1", scd); 
            this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd); 
            //To update the summary. 
            this.gridGroupingControl1.TableDescriptor.EnsureSummaryDescriptors(); 
        } 
    } 
} 
 

Arulraj A 



GP Gregory Pe replied to Arulraj A November 21, 2018 04:12 PM UTC

Hi Gregory, 

Thanks for using Syncfusion product. 

To add the summary while click on the column, you could use the GridTableCellStyleInfo and SummaryRows in TableControlCellClick event. Please refer the following code example, 

Code example 
this.gridGroupingControl1.TableControlCellClick += GridGroupingControl1_TableControlCellClick; 
 
private void GridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e) 
{ 
    if (e.TableControl.CurrentCell.MoveFromColIndex == e.TableControl.CurrentCell.ColIndex) 
        return; 
 
    GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); 
    if (style.CellValueType == typeof(int)) 
    { 
        if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null) 
        { 
            string columnName = style.TableCellIdentity.Column.Name; 
            if (this.gridGroupingControl1.TableDescriptor.SummaryRows.Count > 0) 
                //Clear the previous summary rows to add the  
                this.gridGroupingControl1.TableDescriptor.SummaryRows.Clear(); 
 
            GridSummaryColumnDescriptor scd = new GridSummaryColumnDescriptor(); 
            scd.SummaryType = Syncfusion.Grouping.SummaryType.Int32Aggregate; 
            scd.Format = "{Sum}"; 
            scd.DataMember = columnName; 
            scd.Name = "SumOf" + columnName; 
 
            GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor("Row1", scd); 
            this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd); 
            //To update the summary. 
            this.gridGroupingControl1.TableDescriptor.EnsureSummaryDescriptors(); 
        } 
    } 
} 
 

Arulraj A 


thank you


AA Arulraj A Syncfusion Team November 22, 2018 06:14 AM UTC

Hi Gregory,

Thanks for the update.

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you.

Regards,
Arulraj A


GP Gregory Pe November 22, 2018 06:53 AM UTC

Hi Arulraj A

how to do that
1.
  after clicking the next column, GridSummaryColumnDescripto did not disappear
so that the second, third ...
2.
when we click the second time in the same column - it should disappear only in what we clicked a second time
- when we click the third time it adds again ..


Gregory


AA Arulraj A Syncfusion Team November 22, 2018 12:26 PM UTC

Hi Gregory, 

Thanks for your update. 

Query 
Response 
  

 
 
 
 
 
after clicking the next column, GridSummaryColumnDescripto did not disappear
so that the second, third 
 











To add the new column, you could create the GridsummaryColumnDescriptor for that column the add this summary column in SummaryRows collection.  If want to remove the column from summary columns when click on the same column, you could check and remove that column from SummaryColumns collection. Please refer the following code example 

Code example 
private void GridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e) 
{ 
    GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); 
    if (style.CellValueType == typeof(int)) 
    { 
        if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null) 
        { 
            string columnName = style.TableCellIdentity.Column.Name; 
 
            GridSummaryColumnDescriptor scd = null; 
            if (this.gridGroupingControl1.TableDescriptor.SummaryRows.Count == 0) 
            { 
                scd = AddSummaryColumn(columnName); 
                GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor(); 
                this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd); 
            } 
 
            GridSummaryRowDescriptor summaryRow = this.gridGroupingControl1.TableDescriptor.SummaryRows[0]; 
            var summarycolDescriptor = summaryRow.SummaryColumns.Cast<GridSummaryColumnDescriptor>().Where(x => x.DataMember == columnName); 
            if (summarycolDescriptor.Count() > 0) 
            { 
                var value = summarycolDescriptor.ToList()[0]; 
                summaryRow.SummaryColumns.Remove(value); 
            } 
            else 
            { 
                scd = AddSummaryColumn(columnName); 
                summaryRow.SummaryColumns.Add(scd); 
 
            } 
            //To update the summary. 
            this.gridGroupingControl1.TableDescriptor.EnsureSummaryDescriptors(); 
        } 
    } 
} 
when we click the second time in the same column - it should disappear only in what we clicked a second time 
- when we click the third time it adds again 


Arulraj A 



GP Gregory Pe replied to Arulraj A November 22, 2018 01:03 PM UTC

Hi Gregory, 

Thanks for your update. 

Query 
Response 
  

 
 
 
 
 
after clicking the next column, GridSummaryColumnDescripto did not disappear
so that the second, third 
 











To add the new column, you could create the GridsummaryColumnDescriptor for that column the add this summary column in SummaryRows collection.  If want to remove the column from summary columns when click on the same column, you could check and remove that column from SummaryColumns collection. Please refer the following code example 

Code example 
private void GridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e) 
{ 
    GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); 
    if (style.CellValueType == typeof(int)) 
    { 
        if (style.TableCellIdentity != null && style.TableCellIdentity.Column != null) 
        { 
            string columnName = style.TableCellIdentity.Column.Name; 
 
            GridSummaryColumnDescriptor scd = null; 
            if (this.gridGroupingControl1.TableDescriptor.SummaryRows.Count == 0) 
            { 
                scd = AddSummaryColumn(columnName); 
                GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor(); 
                this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd); 
            } 
 
            GridSummaryRowDescriptor summaryRow = this.gridGroupingControl1.TableDescriptor.SummaryRows[0]; 
            var summarycolDescriptor = summaryRow.SummaryColumns.Cast<GridSummaryColumnDescriptor>().Where(x => x.DataMember == columnName); 
            if (summarycolDescriptor.Count() > 0) 
            { 
                var value = summarycolDescriptor.ToList()[0]; 
                summaryRow.SummaryColumns.Remove(value); 
            } 
            else 
            { 
                scd = AddSummaryColumn(columnName); 
                summaryRow.SummaryColumns.Add(scd); 
 
            } 
            //To update the summary. 
            this.gridGroupingControl1.TableDescriptor.EnsureSummaryDescriptors(); 
        } 
    } 
} 
when we click the second time in the same column - it should disappear only in what we clicked a second time 
- when we click the third time it adds again 


Arulraj A 


Hi Arulraj A

perfectly
thank you for the quick reply


Gregory


AA Arulraj A Syncfusion Team November 23, 2018 04:13 AM UTC

Hi Gregory,

Thanks for the update.

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you.

Regards,
Arulraj A

Loader.
Up arrow icon