|
1 |
| -<!-- default badges list --> |
2 |
| - |
3 |
| -[](https://supportcenter.devexpress.com/ticket/details/T116925) |
4 |
| -[](https://docs.devexpress.com/GeneralInformation/403183) |
5 |
| -<!-- default badges end --> |
6 |
| -<!-- default file list --> |
7 |
| -*Files to look at*: |
8 |
| - |
9 |
| -* **[Default.aspx](./CS/Default.aspx) (VB: [Default.aspx.vb](./VB/Default.aspx.vb))** |
10 |
| -* [Default.aspx.cs](./CS/Default.aspx.cs) (VB: [Default.aspx.vb](./VB/Default.aspx.vb)) |
11 |
| -<!-- default file list end --> |
12 |
| -# ASPxGridView - Batch Edit - How to calculate unbound column and total summary values on the fly |
| 1 | +# Grid View for ASP.NET Web Forms - How to calculate values and update total summaries dynamically in batch edit mode |
13 | 2 | <!-- run online -->
|
14 | 3 | **[[Run Online]](https://codecentral.devexpress.com/t116925/)**
|
15 | 4 | <!-- run online end -->
|
16 | 5 |
|
17 |
| -<p>Starting with v18.2 we support callbacks and keep the changes safe while a user navigates via pages, filters and sorts the grid data. If you use this version and above, please copy/clone the 18.2.3+ branch as approaches to update total summaries differ in new versions and old ones. </p> |
| 6 | +This example demonstrates how to create an unbound column that changes its values based on other column values and replace summary items with custom footer templates to calculate total summaries dynamically in batch edit mode. This example combines the following approaches: |
| 7 | +* [How to calculate values dynamically in batch edit mode](https://github.com/DevExpress-Examples/asp-net-web-forms-gridview-calculate-values-dynamically-batch-mode) |
| 8 | +* [How to update total summaries on the client in batch edit mode](https://github.com/DevExpress-Examples/asp-net-web-forms-grid-update-total-summaries-on-client-in-batch-mode) |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +## Overview |
| 13 | + |
| 14 | +Follow the steps below to calculate column values and update total summaries on the client in batch edit mode: |
| 15 | + |
| 16 | +1. Add total summary items for the corresponding columns. Use the item's [Tag](https://docs.devexpress.com/AspNet/DevExpress.Web.ASPxSummaryItemBase.Tag) property to identify the summary item and get its value. |
| 17 | + |
| 18 | + ```aspx |
| 19 | + <TotalSummary> |
| 20 | + <dx:ASPxSummaryItem SummaryType="Sum" FieldName="Mon" Tag="Mon_Sum" /> |
| 21 | + <dx:ASPxSummaryItem SummaryType="Sum" FieldName="Tue" Tag="Tue_Sum" /> |
| 22 | + <dx:ASPxSummaryItem SummaryType="Sum" FieldName="Wen" Tag="Wen_Sum" /> |
| 23 | + <dx:ASPxSummaryItem SummaryType="Sum" FieldName="Total" Tag="Total_Sum" /> |
| 24 | + </TotalSummary> |
| 25 | + ``` |
| 26 | +
|
| 27 | + ```cs |
| 28 | + protected object GetSummaryValue(string fieldName) { |
| 29 | + ASPxSummaryItem summaryItem = Grid.TotalSummary.First(i => i.Tag == fieldName + "_Sum"); |
| 30 | + return Grid.GetTotalSummaryValue(summaryItem); |
| 31 | + } |
| 32 | + ``` |
| 33 | +
|
| 34 | +2. Set the unbound column's [ShowEditorInBatchEditMode](https://docs.devexpress.com/AspNet/DevExpress.Web.GridDataColumnSettings.ShowEditorInBatchEditMode) property to `false` to make the column read-only in batch edit mode. Replace all summary items with custom [footer templates](https://docs.devexpress.com/AspNet/DevExpress.Web.GridViewColumn.FooterTemplate). |
| 35 | +
|
| 36 | + ```aspx |
| 37 | + <dx:GridViewDataTextColumn FieldName="Total" UnboundType="Decimal" ReadOnly="true"> |
| 38 | + <Settings ShowEditorInBatchEditMode="false" /> |
| 39 | + <FooterTemplate> |
| 40 | + <dx:ASPxLabel ID="ASPxLabel1" runat="server" ClientInstanceName="labelTotal" |
| 41 | + Text='<%# GetSummaryValue((Container.Column as GridViewDataColumn).FieldName) %>' /> |
| 42 | + </FooterTemplate> |
| 43 | + </dx:GridViewDataTextColumn> |
| 44 | + ``` |
| 45 | +
|
| 46 | +3. Handle the grid's client-side [BatchEditEndEditing](https://docs.devexpress.com/AspNet/js-ASPxClientGridView.BatchEditEndEditing), [BatchEditRowDeleting](https://docs.devexpress.com/AspNet/js-ASPxClientGridView.BatchEditRowDeleting), and [BatchEditRowRecovering](https://docs.devexpress.com/AspNet/js-ASPxClientGridView.BatchEditRowRecovering) events to recalculate unbound column values and total summaries. Call the grid's [batchEditApi.GetCellValue](https://docs.devexpress.com/AspNet/js-ASPxClientGridViewBatchEditApi.GetCellValue(visibleIndex-columnFieldNameOrId)) method to get initial cell values and the [batchEditApi.SetCellValue](https://docs.devexpress.com/AspNet/js-ASPxClientGridViewBatchEditApi.SetCellValue(visibleIndex-columnFieldNameOrId-value)) method to assign new values to the unbound column. |
| 47 | +
|
| 48 | +## Files to Review |
| 49 | +
|
| 50 | +* [Default.aspx](./CS/Default.aspx) (VB: [Default.aspx.vb](./VB/Default.aspx.vb)) |
| 51 | +* [Default.aspx.cs](./CS/Default.aspx.cs) (VB: [Default.aspx.vb](./VB/Default.aspx.vb)) |
18 | 52 |
|
19 |
| -<p>This example illustrates how to calculate unbound column and total summary values on the fly. It combines the following two examples: <a href="https://www.devexpress.com/Support/Center/p/T114923">ASPxGridView - How to update total summaries on the client side in Batch Edit mode</a> and <a href="https://www.devexpress.com/Support/Center/p/T114539">ASPxGridView - Batch Edit - How to calculate values on the fly</a>.<br /><br /><strong>ASP.NET MVC Example:</strong><br /><a href="https://www.devexpress.com/Support/Center/p/T124151">GridView - Batch Edit - How to calculate unbound column and total summary values on the fly</a> </p> |
| 53 | +## Documentation |
20 | 54 |
|
21 |
| -<br/> |
| 55 | +* [Grid in Batch Edit Mode](https://docs.devexpress.com/AspNet/16443/components/grid-view/concepts/edit-data/batch-edit-mode) |
| 56 | +* [Grid View Templates](https://docs.devexpress.com/AspNet/3718/components/grid-view/concepts/templates) |
22 | 57 |
|
| 58 | +## More Examples |
23 | 59 |
|
| 60 | +* [Grid View for ASP.NET MVC - How to calculate values and update total summaries dynamically in batch edit mode](https://github.com/DevExpress-Examples/gridview-batch-edit-how-to-calculate-unbound-column-and-total-summary-values-on-the-fly-t124151) |
0 commit comments