We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Asp.net mvc-EjGrid


how to sum the particular column values in grid

6 Replies

SR Sellappandi Ramu Syncfusion Team February 27, 2015 06:29 AM UTC

Hi Ganga,

Thanks for your interest in Syncfusion products.

We have analyzed your requirement for “Sum the particular column values in grid” and created a sample. The sample can be downloaded from following link:

Sample: http://www.syncfusion.com/downloads/support/directtrac/118335/MvcGrid685789389.zip

For your information, Grid control has the default property of ShowSummary. Using ShowSummary property to aggregate a particular column. Please refer the following code snippet.

@(Html.EJ().Grid<MvcGrid.OrdersView>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

        .AllowScrolling()

        .ShowSummary()

        .SummaryRow(row =>

        {

            row.Title("Sum").SummaryColumns(col =>

            {

col.SummaryType(SummaryType.Sum).Format("{0:C}").DisplayColumn("Freight").DataMember("Freight").Add();

            }).Add();

        })

        .Columns(col =>

        {

                                ….           

        }))

For your reference we have provided the online link below.

Online sample link: http://mvc.syncfusion.com/demos/web/grid/summary

Online help documentation: http://help.syncfusion.com/ug/js/documents/summary1.htm

Please try the above sample and get back to us if you have any queries.

Regards,

Sellappandi R


GA Ganga February 27, 2015 01:13 PM UTC

Sorry .I can't get this correctly..Is there any other way to show that total value in a text box ???


GA Ganga February 28, 2015 06:36 AM UTC

Thankz For Sending.
its appending my values. for example 35,34=3534..
How to solve this


SR Sellappandi Ramu Syncfusion Team March 2, 2015 02:25 PM UTC

Hi Ganga,

Thanks for your interest in Syncfusion products.

Query #1: Its appending my values, How to solve this?

We have analyzed your reported issue at our end and we would like you to share the following information to us to sort out the cause of the issue.

1. Please share your data source to us.

2. Could you please replicate the issue in the attached sample or kindly provide the issue reproducing sample?

We are unable to reproduce the issue while testing the sample by using string type of value to column, even summary row displayed the sum values. Because using showSummary property, we are converted string  value to number format on before aggregate.

Query #2: Is there any other way to show that total value in a text box ???

We have created the sample based on your requirement and the sample can be downloaded from following link:

Sample Link: http://www.syncfusion.com/downloads/support/directtrac/118335/MvcGrid1151188107.zip

In the provided sample we have used create event to hide the summary row and display the sum value to text box. Please refer the following code snippet.

@(Html.EJ().Grid<MvcGrid.OrdersView>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

        .AllowScrolling()

        .ShowSummary()

        .EditSettings(e=>e.AllowEditing())

        .SummaryRow(row =>

        {

            row.Title("Sum").SummaryColumns(col =>

            {

                col.SummaryType(SummaryType.Sum).DisplayColumn("ShipPostalCode").DataMember("ShipPostalCode").Add();

            }).Add();

        })

        .Columns(col =>

        {

                ….

        }).ClientSideEvents(e => e.Create("create").ActionComplete("create")))

<div>

    <table><tbody><tr><td>Sum of Frieght:</td><td>@Html.EJ().NumericTextbox("numeric")</td></tr></tbody></table>

</div>

<script>

    function create(args) {

        var gridObj = $("#FlatGrid").ejGrid("instance");

        gridObj.element.find(".e-gridsummary").addClass("e-hide");

        $("#numeric").val($(gridObj.element.find(".e-gridsummary .e-summaryrow")[gridObj.getColumnIndexByField("ShipPostalCode")]).html());

    }

</script>

Please try the above sample and get back to us with the mentioned details.

Regards,

Sellappandi R


GA Ganga March 28, 2015 05:09 AM UTC

Thank u sir.It's Working Fine.


SR Sellappandi Ramu Syncfusion Team March 30, 2015 02:13 PM UTC

Hi Ganga,

Thanks for the update.

Please get back to us if you need any further assistance.

Regards,

Sellappandi R

Loader.
Live Chat Icon For mobile
Up arrow icon