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

Custom summary on Grouped rows

Hi,
I Have an OData V4 Paged bound grid.
I Group for a column and want to show some totals on the Summary rows of group.
My first problem is that the normal sum is calculated on the grid page data, and if the group is spread across pages I have not the real values on the totals.
I tried with the custom Summary, trying to call an ODATA function to calculate the correct data o the server,, but I don't know how to retrieve, in the custom javascript function the current value of the group where the summary row is calculated.
There is any solution for my problem?

      Thanks in advance

     Andrea Perazzolo

3 Replies

MS Mani Sankar Durai Syncfusion Team October 27, 2016 06:22 AM UTC

Hi Andrea, 
 
 
Thanks for contacting Syncfusion support. 
 
 
While using ODataV4 adaptors we can get only current page data, so we can’t get aggregates for entire grouped records which are in next page too. Suppose if you want to show aggregate for entire dataSource while using ODataV4Adaptor then we need to send multiple post to server to get the entire data and then send the aggregate through adaptor, so this is not feasible and currently we don’t have support for this by default. Hence we suggest you to use UrlAdaptor instead of ODataV4Adaptor to display the aggregate for whole dataSource. 
 
Please refer the documentation link of about how to use aggregate in UrlAdaptor. 
 
 
 
Regards, 
Manisankar Durai. 



AP Andrea Perazzolo October 27, 2016 06:36 AM UTC

Thanks for the reply.
I'll ask if there is a way to access the current grouped data in the function that is used to calculate the summary value in the custom summary.
It will be sufficient for me for calling a server function that calculate the whole total for the group.

      Thanks in advance

     Andrea Perazzolo


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team October 28, 2016 02:27 PM UTC

Hi Andrea, 

We cannot achieve your requirement using the Odata service. But we can achieve it using the UrlAdaptor. Refer to the following code example. 

namespace MvcApplication66.Controllers 
{ 
    public class HomeController : Controller 
    { 
        public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm) 
        { 
 
            IEnumerable datasource = new NorthwindDataContext().EmployeeViews.ToList(); 
            DataResult result = new DataResult(); 
            DataOperations operation = new DataOperations(); 
            . . .. . .  
            List<string> str1 = new List<string>(); 
            List<string> str = new List<string>(); 
            if (dm.Aggregates != null) 
            { 
                for (var i = 0; i < dm.Aggregates.Count; i++) 
                    str.Add(dm.Aggregates[i].Field); 
                result.aggregate = operation.PerformSelect(datasource, str); 
            } 
            if (dm.Group != null) { 
                for (var i = 0; i < dm.Group.Count; i++) 
                    str1.Add(dm.Group[i]); 
                result.groupDs = operation.PerformSelect(DataSource, str1); 
                if (dm.Aggregates != null) 
                { 
                    for (var i = 0; i < dm.Aggregates.Count; i++) {  
                        if(str1.IndexOf(dm.Aggregates[i].Field)==-1) 
                            str1.Add(dm.Aggregates[i].Field); 
                    } 
                    result.groupDs = operation.PerformSelect(DataSource, str1); 
                } 
            } 
            result.count = count; 
            result.result = datasource; 
            return Json(result, JsonRequestBehavior.AllowGet); 
        } 
    } 
} 
 
        public class DataResult 
        { 
            public IEnumerable result { get; set; } 
            public int count { get; set; } 
            public IEnumerable aggregate { get; set; } 
            public IEnumerable groupDs { get; set; } 
        } 
 
<div id="Grid"></div> 
<script type="text/javascript"> 
    $(function () { 
        $("#Grid").ejGrid({ 
            dataSource: ej.DataManager({ 
                url: "/Home/DataSource", 
                adaptor: new ej.UrlAdaptor() 
            }), 
            summaryRows: [ 
                    { title: "Sum", summaryColumns: [{ summaryType: ej.Grid.SummaryType.Sum, displayColumn: "Freight", dataMember: "Freight", format: "{0:C2}" }] }, 
                                 . .  
            ], 
        }); 
    }); 
</script> 

The above code example handles the data for Total summary as well as the Group summary of the Grid. 

Regards, 
Seeni Sakthi Kumar S.  


Loader.
Live Chat Icon For mobile
Up arrow icon