This example demonstrates how to replace a summary item with a custom footer template to calculate the total summary dynamically in batch edit mode. In this example, the grid's HighlightDeletedRows property is set to false
.
-
Add a total summary item for the corresponding column. Use the item's Tag property to identify the summary item and get its value.
<TotalSummary> <dx:ASPxSummaryItem SummaryType="Sum" FieldName="C2" Tag="C2_Sum" /> </TotalSummary>
protected object GetTotalSummaryValue() { ASPxSummaryItem summaryItem = Grid.TotalSummary.First(i => i.Tag == "C2_Sum"); return Grid.GetTotalSummaryValue(summaryItem); }
-
Replace the summary item with a custom footer template.
<dx:GridViewDataSpinEditColumn Width="100" FieldName="C2"> <FooterTemplate> Sum = <dx:ASPxLabel ID="ASPxLabel1" runat="server" ClientInstanceName="labelSum" Text='<%# GetTotalSummaryValue() %>' /> </FooterTemplate> </dx:GridViewDataSpinEditColumn>
-
Handle the grid's client-side BatchEditEndEditing and BatchEditRowDeleting events. In handlers, use the grid's batchEditApi.GetCellValue method to get initial cell values and
rowValues
argument property to get new cell values. Then recalculate the summary value and assign it to the label.function OnBatchEditEndEditing(s, e) { CalculateSummary(s, e.rowValues, e.visibleIndex, false); } var savedValue; function CalculateSummary(grid, rowValues, visibleIndex, isDeleting) { var originalValue = grid.batchEditApi.GetCellValue(visibleIndex, "C2"); var newValue = rowValues[(grid.GetColumnByField("C2").index)].value; var dif = isDeleting ? -newValue : newValue - originalValue; var sum = (parseFloat(labelSum.GetValue()) + dif).toFixed(1); savedValue = sum; labelSum.SetValue(sum); } function OnBatchEditRowDeleting(s, e) { CalculateSummary(s, e.rowValues, e.visibleIndex, true); }
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx)
- Grid View for ASP.NET MVC - How to update total summaries on the client in batch edit mode
- Grid View for ASP.NET Web Forms - How to calculate values dynamically in batch edit mode
- Grid View for ASP.NET Web Forms - How to calculate values and total summaries dynamically in batch edit mode
- Grid View for ASP.NET Web Forms - How to update total summaries in batch edit mode when deleted rows are highlighted
(you will be redirected to DevExpress.com to submit your response)