Coder Social home page Coder Social logo

devexpress-examples / gridview-how-to-update-total-summaries-on-the-client-side-in-batch-edit-mode-t137186 Goto Github PK

View Code? Open in Web Editor NEW
0.0 54.0 2.0 541 KB

Replace a summary item with a custom footer template to calculate the total summary dynamically in batch edit mode.

License: Other

C# 27.37% HTML 15.90% ASP.NET 0.79% Visual Basic .NET 55.94%
dotnet mvc-gridview asp-net-mvc batch-editing summary template

gridview-how-to-update-total-summaries-on-the-client-side-in-batch-edit-mode-t137186's Introduction

Grid View for ASP.NET MVC - 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.

Update total summaries

Overview

Follow the steps below to update total summaries on the client in batch edit mode:

  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.

    settings.Columns.Add(column => {
    column.FieldName = "C2";
    column.ColumnType = MVCxGridViewColumnType.SpinEdit;
    
    ASPxSummaryItem summaryItem = new ASPxSummaryItem(column.FieldName, DevExpress.Data.SummaryItemType.Sum);
    summaryItem.Tag = column.FieldName + "_Sum";
    summaryItem.DisplayFormat = "{0}";
    settings.TotalSummary.Add(summaryItem);
    });
  2. Replace the summary item with a custom footer template.

    column.SetFooterTemplateContent(c => {
    	Html.DevExpress().Label(lbSettings => {
    		string fieldName = (c.Column as GridViewDataColumn).FieldName;
    		lbSettings.Name = "labelSum";
    		lbSettings.Properties.EnableClientSideAPI = true;
    		ASPxSummaryItem summaryItem1 = c.Grid.TotalSummary.First(i => i.Tag == (fieldName + "_Sum"));
    		lbSettings.Text = c.Grid.GetTotalSummaryValue(summaryItem1).ToString();
    	}).Render();
    });
  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);
    }
    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;
        labelSum.SetValue((parseFloat(labelSum.GetValue()) + dif).toFixed(1));
    }
    function OnBatchEditRowDeleting(s, e) {
        CalculateSummary(s, e.rowValues, e.visibleIndex, true);
    }
    function OnChangesCanceling(s, e) {
        if (s.batchEditApi.HasChanges())
            setTimeout(function () {
                s.Refresh();
            }, 0);
    }

Files to Review

Documentation

More Examples

gridview-how-to-update-total-summaries-on-the-client-side-in-batch-edit-mode-t137186's People

Contributors

devexpressexamplebot avatar elenapeskova avatar mikhailtymchukdx avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.