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

Summary Columns

Hi,
I am trying to get 2 summary columns to work on my grid but they only displays 0's.
Here the code from my view:

@(Html.EJ().Grid<ShoNuffModelClass.DailyPatientType>("DayOnePatientTypes")

                   .Datasource(ds => ds.URL("Report/DayOneGet").Adaptor(AdaptorType.UrlAdaptor))
                    .EnableAltRow()
        .ScrollSettings(col => { col.Width(200).Height(275); })
       
       
        .Columns(col =>
        {
            col.Field("ID").HeaderText("ID").Width("50px").Visible(false).IsPrimaryKey(true).DefaultValue(1).Add();
            col.Field("PatientType").HeaderText("Pat Type").Width("55px").IsPrimaryKey(true).Add();
            col.Field("PatientStartCount").HeaderText("Start").Width("30px").Add();
            col.Field("PatientEndCount").HeaderText("End").Width("30px").Add();
            col.Field("Percentage").HeaderText("").Width("30px").Add();


        })
         .ShowSummary()

          .SummaryRow(row =>
        {
            row.Title("").SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("PatientStartCount").DataMember("PatientStartCount").Add(); })
                         .SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("PatientEndCount").DataMember("PatientEndCount").Add(); }).Add();
        })

              .ClientSideEvents(eve => { eve.Create("createDayOne").Load("loadDayOne"); })
            )

The rest of my grid displays correctly.

5 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team May 12, 2017 05:57 AM UTC

Hi Richard, 
 
Thanks for contacting Syncfusion support. 
 
In your code example we found that you have used URL Adaptor in your sample. While using remote data, Summary Row must be handled by returning summary column datasource into the aggregate property of result object.  
 
Find the code example and sample:  
 
 
@(Html.EJ().Grid<object>("Grid")
    .Datasource(d => d.URL("/Home/GetData").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor))
    .EnableAltRow()
    .ScrollSettings(col => { col.Width(200).Height(275); })
    .Columns(col =>
     {
         -------------------------------------
 
     })
     .ShowSummary()
     .SummaryRow(row =>
      {
          row.Title("").SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("Variance").DataMember("Variance").Add(); })
                .SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("TillNumber").DataMember("TillNumber").Add(); }).Add();
      })
     .ClientSideEvents(eve => { eve.Create("createDayOne").Load("loadDayOne"); })
)
 
 
-------------------------------------------------------- 
 
public ActionResult GetData(DataManager dm)
        {
            -----------------------------------------
            if (dm.Aggregates != null)
            {
                for (var i = 0; i < dm.Aggregates.Count; i++)
                    str.Add(dm.Aggregates[i].Field);
                result.aggregate = ds.PerformSelect(DataSource, str);
            }
            result.result = ds.Execute(DataSource, dm);
            result.count = DataSource.AsQueryable().Count();
            return Json(result, JsonRequestBehavior.AllowGet);      
        }
 
 
 
For more information refer to the below help document.  
 
 
Regards, 
Prasanna Kumar N.S.V




RD Richard Dublon May 12, 2017 06:16 PM UTC

Hi,
This worked well for generating a summary row but I am now getting the following error for a random amount of my grids each time I run my project(I have 5 small grids on my page):

An exception of type 'System.ArgumentException' occured in mscorlib.dll but was not handled in user code.
Additional information: An item with the same key has already been added.

The error occurs here:
      if (dm.Aggregates != null)
      {
            for (var i = 0; i < dm.Aggregates.Count; i++)
                    str.Add(dm.Aggregates[i].Field);
             result.aggregate = ds.PerformSelect(DataSource, str);
       }

Is it because I have multiple grids on the same page?  



TS Thavasianand Sankaranarayanan Syncfusion Team May 15, 2017 12:45 PM UTC

Hi Richard, 

We have analyzed your query and we are unable to reproduce the reported issue “An exception of type 'System.ArgumentException' occured in mscorlib.dll but was not handled in user code” from our end. 

We have prepared a sample with five Grids in a same page and it can be downloadable form the below location. 


So, please share the following details for better assistance. 

  1. Share the screen shot or video demonstration of the issue.
  2. Share the Grid code example.
  3. Essential studio version.
  4. Share the stacktrace of the issue if any script occur.
  5. If possible share the sample or reproduce the issue in the attached sample.
 
Regards, 
Thavasianand S. 



RD Richard Dublon May 24, 2017 07:34 PM UTC

Hi,
Your example is a little different than mine because in your example, you have all of the grids using the same name.  Since my application is based on days of the week, I cannot do that so I have different names(and therefore different controller methods).  Here are two of the grids in my view(the other 3 are the same structure but named day3, day4, and day5).

<div class="col-md-5ths">
@(Html.EJ().Grid<ShoNuffModelClass.DailyPatientType>("DayOnePatientTypes")

                   .Datasource(ds => ds.URL("OfficeAdmin/DayOneGet").BatchURL("OfficeAdmin/InsertUpdate").Adaptor(AdaptorType.UrlAdaptor))
                    .EnableAltRow()
        .ScrollSettings(col => { col.Width(200).Height(275); })
        .EnableAutoSaveOnSelectionChange(false)
        .EditSettings(edit => { edit.AllowEditing().AllowEditOnDblClick(false).EditMode(EditMode.Batch); })
        .ToolbarSettings(toolbar =>
        {
            toolbar.ShowToolbar().ToolbarItems(items =>
            {
                items.AddTool(ToolBarItems.Edit);
                items.AddTool(ToolBarItems.Update);
                items.AddTool(ToolBarItems.Cancel);
            });
        })
        .Columns(col =>
        {
            col.Field("ID").HeaderText("ID").Width("50px").Visible(false).IsPrimaryKey(true).DefaultValue(1).Add();
            col.Field("PatientType").HeaderText("Pat Type").Width("55px").IsPrimaryKey(true).Add();
            col.Field("PatientStartCount").HeaderText("Start").Width("30px").Add();
            col.Field("PatientEndCount").HeaderText("End").Width("30px").Add();

        })
         .ShowSummary()

          .SummaryRow(row =>
        {
            row.ShowTotalSummary(true);
            row.Title("Totals: ").SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("PatientStartCount").DataMember("PatientStartCount").Add(); })
                         .SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("PatientEndCount").DataMember("PatientEndCount").Add(); }).Add();
        })

              .ClientSideEvents(eve => { eve.Create("createDayOne").Load("loadDayOne"); })
            )
            
        </div>


        <div class="col-md-5ths">


            @(Html.EJ().Grid<ShoNuffModelClass.DailyPatientType>("DayTwoPatientTypes")

                   .Datasource(ds => ds.URL("OfficeAdmin/DayTwoGet").BatchURL("OfficeAdmin/InsertUpdate").Adaptor(AdaptorType.UrlAdaptor))
                    .EnableAltRow()
        .ScrollSettings(col => { col.Width(200).Height(275); })
        .EnableAutoSaveOnSelectionChange(false)
        .EditSettings(edit => { edit.AllowEditing().AllowEditOnDblClick(false).EditMode(EditMode.Batch); })
        .ToolbarSettings(toolbar =>
        {
            toolbar.ShowToolbar().ToolbarItems(items =>
            {
                items.AddTool(ToolBarItems.Edit);
                items.AddTool(ToolBarItems.Update);
                items.AddTool(ToolBarItems.Cancel);
            });
        })
        .Columns(col =>
        {
            col.Field("ID").HeaderText("ID").Width("50px").Visible(false).IsPrimaryKey(true).DefaultValue(2).Add();
            col.Field("PatientType").HeaderText("Pat Type").Width("55px").IsPrimaryKey(true).Add();
            col.Field("PatientStartCount").HeaderText("Start").Width("30px").Add();
            col.Field("PatientEndCount").HeaderText("End").Width("30px").Add();

        })
         .ShowSummary()

          .SummaryRow(row =>
        {
            row.ShowTotalSummary(true);
            row.Title("Totals: ").SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("PatientStartCount").DataMember("PatientStartCount").Add(); })
                         .SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("PatientEndCount").DataMember("PatientEndCount").Add(); }).Add();
        })

              .ClientSideEvents(eve => { eve.Create("createDayTwo").Load("loadDayTwo"); })
            ) 

        </div>

Here is my controller code:

  public ActionResult Index()
        {

            //var snContext = new ShoNuffEntities();

            //var result = from pt in snContext.PatientTypes
            //             select new
            //             {
            //                 PatientType = pt.Description,
            //                 PatientCount = 0

            //             };
            //ViewBag.dataSource = result.ToList();

            return View();
        }

        public IEnumerable LoadGrid(string day)
        {

            DateTime getDay = GetDate(day);

            var DataSource = from pt in sndc.PatientTypes
                             join vis in sndc.OfficeVisits on pt.ID equals vis.PatientTypeID into vispt
                             from vpt in vispt.Where(v => v.VisitDate == getDay).DefaultIfEmpty()
                             select new
                             {
                                 ID = pt.ID,
                                 PatientType = pt.Description,
                                 PatientStartCount = (int?)vpt.PatientStartCount,
                                 PatientEndCount = (int?)vpt.PatientEndCount
                             };

            IEnumerable result = DataSource;
          
            return result;
        }


        public ActionResult DayOneGet(DataManager dm)
        {
            DataOperations ds = new DataOperations();
            List<string> str = new List<string>();
            DataResult result = new DataResult();

            IEnumerable DataSource = LoadGrid("Day1");

            if (dm.Aggregates != null)
            {
                for (var i = 0; i < dm.Aggregates.Count; i++)
                    str.Add(dm.Aggregates[i].Field);
                result.aggregate = ds.PerformSelect(DataSource, str);
            }
            result.result = ds.Execute(DataSource, dm);
            result.count = DataSource.AsQueryable().Count();
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        public ActionResult DayTwoGet(DataManager dm)
        {
            DataOperations ds = new DataOperations();
            List<string> str = new List<string>();
            DataResult result = new DataResult();

            IEnumerable DataSource = LoadGrid("Day2");

            if (dm.Aggregates != null)
            {
                for (var i = 0; i < dm.Aggregates.Count; i++)
                    str.Add(dm.Aggregates[i].Field);
                result.aggregate = ds.PerformSelect(DataSource, str);
            }
            result.result = ds.Execute(DataSource, dm);
            result.count = DataSource.AsQueryable().Count();
            return Json(result, JsonRequestBehavior.AllowGet);
        }

Is there a way to pass the grid name to the controller?  If I can do that then I would be able to use the same controller method for all 5 grids which might solve my problem.



PK Prasanna Kumar Viswanathan Syncfusion Team May 25, 2017 09:20 AM UTC

Hi Richard, 

Query : “Is there a way to pass the grid name to the controller?” 

Yes, you can pass the grid name to the controller. To pass an additional parameter to an controller action, use the query API.  In this sample we pass the parameter in addParams property using query API. 

Find the code example and sample:  


<div class="col-md-5ths"> 
    @(Html.EJ().Grid<object>("DayOnePatientTypes") 
        .Datasource(ds => ds.URL("/Home/GetData").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor)) 
        .Query("new ej.Query().addParams('Id', 'DayOnePatientTypes')")  
            ------------------ 
</div> 
 
 
<div class="col-md-5ths"> 
 
 
    @(Html.EJ().Grid<object>("DayTwoPatientTypes") 
        .Datasource(ds => ds.URL("/Home/GetData").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor)) 
        .Query("new ej.Query().addParams('Id', 'DayTwoPatientTypes')")  
         ------------------- 
    ) 
 
</div> 
 
<div class="col-md-5ths"> 
    @(Html.EJ().Grid<object>("DayThreePatientTypes") 
        .Datasource(ds => ds.URL("/Home/GetData").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor)) 
        .Query("new ej.Query().addParams('Id', 'DayThreePatientTypes')") 
        --------------------------------- 
         
 
</div> 
 
 
<div class="col-md-5ths"> 
 
 
    @(Html.EJ().Grid<object>("DayFourPatientTypes") 
        .Datasource(ds => ds.URL("/Home/GetData").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor)) 
        .Query("new ej.Query().addParams('Id', 'DayFourPatientTypes')") 
        ----------------------------- 
         
    ) 
 
</div> 
<div class="col-md-5ths"> 
 
 
    @(Html.EJ().Grid<object>("DayFivePatientTypes") 
        .Datasource(ds => ds.URL("/Home/GetData").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor)) 
        .Query("new ej.Query().addParams('Id', 'DayFivePatientTypes')") 
        ------------------------------- 
        
    ) 
 
</div> 
 
--------------------------------------------------------- 

public ActionResult GetData(DataManager dm, string id) 
        { 
            IEnumerable DataSource = OrderRepository.GetAllRecords().ToList(); 
             ---------------- 
        } 


For more information, refer the below help documents.  



Regards, 
Prasanna Kumar N.S.V 


Loader.
Up arrow icon