Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

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

$
0
0

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 ASPxGridView.CustomUnboundColumnData Event help article:

[ASPx]
<dx:GridViewDataTextColumnFieldName="Sum"UnboundType="Decimal"ReadOnly="true"></dx:GridViewDataTextColumn>
[C#]
protectedvoidGrid_CustomUnboundColumnData(objectsender,ASPxGridViewColumnDataEventArgse){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:

ASPxGridView - How to update total summaries on the client side in Batch Edit mode
ASPxGridView - Batch Edit - How to calculate unbound column and total summary values on the fly 

ASP.NET MVC Example:
GridView - Batch Edit - How to calculate values on the fly


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>