This is a migrated thread and some comments may be shown as answers.

sum and aggregate doesn't work

2 Answers 347 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phongsathorn
Top achievements
Rank 1
Phongsathorn asked on 01 Feb 2013, 12:58 PM

I want to sum my orders as GrandTotal, But my grid cannot do it.
Grand Total row is always 0
Please help Urgent

Big Thanks

my grid

@(Html.Kendo().Grid((IEnumerable<Apex.Models.bmfsummary>)ViewData["BMFsummary"])
    .Name("Grid")
    
    .Columns(cols =>
    {
 
        cols.Bound(ss => ss.eventdate).Title("Date").ClientFooterTemplate("Grand Total");
        cols.Bound(ss => ss.totalPrice).Title("Total").Format("{0:n2}").ClientFooterTemplate("#=sum#");
 
         
 
    })
 
 .DataSource(dataSource =>
               dataSource.Ajax()
                          
                         .Aggregates(aggregates => { aggregates.Add(ss => ss.totalPrice).Sum(); } )
                          
                         .Read(read => read.Action("Summary", "BMF"))
)

2 Answers, 1 is accepted

Sort by
0
Phongsathorn
Top achievements
Rank 1
answered on 01 Feb 2013, 01:00 PM
my controller and model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
 
using System.IO;
 
namespace Apex.Controllers
{
    public class BMFController : Controller
    {
        //
        // GET: /BMF/
 
        public ActionResult Index()
        {
            return View();
        }
 
        public ActionResult Summary()
        {
           var _context = new Data.AxaptaContextDataContext();
           var bmfsummary = from e in _context.APEX_SalesLineDetail_PSOs
                            group e by new { e.INVOICEDATE } into myGroup
                         
                            select new Models.bmfsummary
                            {
                               eventdate = myGroup.Key.INVOICEDATE.Date.ToShortDateString(),
                                totalPrice = myGroup.Sum(n=>n.Total_Sales_Price).Value
                        
                            };
 
    
            ViewData["BMFsummary"] = bmfsummary.ToList();
 
            return View();
        }
    }
}
 
/********* MODEL**********/
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace Apex.Models
{
    public class bmfsummary
    {
        public Decimal totalPrice { get; set; }
        public string eventdate { get; set; }
          
    }
}
0
Rosen
Telerik team
answered on 05 Feb 2013, 08:01 AM
Hi Phongsathorn,

Looking at the code you have provided it seems that the grid is not bind correctly. This is due to incorrect implementation of the Action method responsible for providing the data. Please refer to this help article on how to setup AJAX binding.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Phongsathorn
Top achievements
Rank 1
Answers by
Phongsathorn
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or