Skip to content

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.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-web-forms-grid-update-total-summaries-on-client-in-batch-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to update total summaries on the client in batch edit mode

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.

Update total summaries

Overview

  1. 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);
    }
  2. 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>
  3. 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);
    }

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •