Skip to content

onebalaban/gridview-batch-edit-how-to-calculate-values-on-the-fly-t124603

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GridView - Batch Edit - How to calculate values on the fly

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.

You can find detailed steps by clicking below the "Show Implementation Details" link .


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

Description

Starting with v16.1, it's possible to modify cells without highlighting using the corresponding ASPxClientGridViewBatchEditApi.SetCellValue method overload and make a column non-editable for a user using the GridDataColumnSettings.ShowEditorInBatchEditMode property.

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:
settings.Columns.Add(column =>{ column.UnboundType = DevExpress.Data.UnboundColumnType.Decimal; column.FieldName = "Sum"; column.ReadOnly = true; column.Settings.ShowEditorInBatchEditMode = false; });

settings.CustomUnboundColumnData = (sender, e) => { if (e.Column.FieldName == "Sum") { decimal price = Convert.ToDecimal(e.GetListSourceFieldValue("Price")); int quantity = Convert.ToInt32(e.GetListSourceFieldValue("Quantity")); e.Value = price * quantity; } };

 

 2. 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:

function OnBatchEditEndEditing(s, e) { var PriceColIndex = s.GetColumnByField("Price").index; var QuantityColIndex = s.GetColumnByField("Quantity").index; var priceValue = e.rowValues[PriceColIndex].value; var quantityValue = e.rowValues[QuantityColIndex].value; s.batchEditApi.SetCellValue(e.visibleIndex, "Sum", priceValue * quantityValue, null, true); }

About

.NET, ASP.NET MVC, MVC GridView

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 82.6%
  • C# 17.2%
  • Classic ASP 0.2%