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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to sum all the values in a column and display it in an external input box in the BatchEditing?

In certain cases, while dynamic editing you may want to sum all the values in a column and display it in an input text box.

Solution

You can achieve the above requirement by using create and cellSave events or an external button click event with the Sum summary type.

The create event is triggered when the Grid has rendered completely. In the argument of the create event, you can obtain the following details.

Name

Description

cancel

Returns the cancel option value

model

Returns the Grid model

type

Returns the name of the event

 

The cellSave event is triggered when a cell is edited and saved on batchEdit mode. In the argument of the cellSave event, you can obtain the following details.

Name

Description

model

Returns the Grid model

type

Returns the name of the event

data

Returns the deleted data

columnName

Returns the column name

rowData

Returns the row data object

value

Returns the modified cell value

previousValue

Returns the previous value of the cell

columnObject

Returns the columnObject

cell

Returns the cell object

isForeignKey

Returns when the edited column is ForeignKey

 

The Sum Summary type yields the sum of the data. The parameters of the ej.sum are listed in the following table

Parameter

Description

DataSource

Json data where the sum operation is to be performed

Column/Field Name

Corresponding field name for calculating the sum

 

Example:

In the following example, the Grid is rendered with batch editing enabled.

  1. Render the Grid.

 

MVC

 

ASP.NET

  1. Render the input control for displaying the sum calculated.

 

  1. In the create event, the sum of all the values in the Freight column is obtained by using ej.Sum summary type and displayed in the input text box.
  1. In the cellSave event, when the cell value is edited and saved, the edited value is obtained. The difference of the edited value compared to the default value of the cell is added to the original sum.

Result:

Figure 1: Initial Rendering

Note: The sum of the Freight column is calculated and displayed in the input text box.

Figure 2: After Editing and saving a cell

Article ID: Published Date: Last Revised Date: Platform: Control:
3830 02/10/2015 08/06/2015 ASP.NET MVC Grid
Did you find this information helpful?
Comments
Steve Davey Oct 12, 2015
Every example you show with foreign keys is badly done. NO ONE would EVER display key fields in a grid - they are useless. Your ASP.NET MVC project template is the same. Your controls may be good, but your documentation is poor
Reply
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon