This example demonstrates how to create an unbound column that calculates the sum of other columns and changes its values on the fly when end-user changes any grid values using Batch edit mode.
To implement the required task, perform the following steps:
1. Create an unbound column in the same manner as described in the Unbound Columns help article:
To implement the required task, perform the following steps:
1. Create an unbound column in the same manner as described in the Unbound Columns help article:
[C#]settings.Columns.Add(column=>{column.UnboundType=DevExpress.Data.UnboundColumnType.Decimal;column.FieldName="Sum";column.ReadOnly=true;});settings.CustomUnboundColumnData=(sender,e)=>{if(e.Column.FieldName=="Sum"){decimalprice=Convert.ToDecimal(e.GetListSourceFieldValue("Price"));intquantity=Convert.ToInt32(e.GetListSourceFieldValue("Quantity"));e.Value=price*quantity;}};
2. Handle the client-side ASPxClientGridView.BatchEditStartEditing event to save the currently edited column name as a global JavaScript variable:
[JScript]var currentColumnName;function OnBatchEditStartEditing(s, e){ currentColumnName = e.focusedColumn.fieldName;}
3. Handle the ASPxClientGridView.BatchEditEndEditing event to re-calculate the values based on the new changes and set it to the unbound column using the ASPxClientGridViewBatchEditApi.SetCellValue method:
[JScript]function OnBatchEditEndEditing(s, e){ window.setTimeout(function(){var price = s.batchEditApi.GetCellValue(e.visibleIndex, "Price");var quantity = s.batchEditApi.GetCellValue(e.visibleIndex, "Quantity"); s.batchEditApi.SetCellValue(e.visibleIndex, "Sum", price * quantity);}, 10);}
See Also:
GridView - Batch Edit - How to calculate unbound column and total summary values on the fly
ASP.NET Web Forms Example:
ASPxGridView - Batch Edit - How to calculate values on the fly