- Home
- Forum
- ASP.NET MVC
- Summary Column
Summary Column
Hi,
I am having some trouble getting my summary column to work. All I ever see is a 0.
Here is my grid declaration:
@(Html.EJ().Grid<object>("MasterGrid")
.ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.ExcelExport);
}))
.Mappers(map => map.ExportToExcelAction("Reports/ExportMasterGrid"))
.ClientSideEvents(events => events.Load("onLoad").DataBound("dataBound"))
.Datasource(ds => ds.URL(@Url.Action("DataSource"))
.Adaptor(AdaptorType.UrlAdaptor))
.AllowPaging()
.AllowSorting()
.AllowFiltering()
.EnableAltRow()
.ShowSummary()
.SummaryRow(row =>
{
row.Title("Count").SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("LeadCount").DataMember("LeadCount").Add(); }).Add();
})
.Columns(col =>
{
col.Field("State").HeaderText("State").Add();
col.Field("MailDate").HeaderText("Mail Date").Format("{0:M/d/yyyy}").Add();
col.Field("LeadCount").HeaderText("Lead Count").Add();
})
.ClientSideEvents(eve => { eve.RowSelected("rowSelected"); })
)
Here is my c# code:
public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm)
{
int count = 0;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
string JSONString = null;
using (SqlConnection cn = new SqlConnection(connStr))
{
cn.Open();
//Getting the records based on skip and top value.
SqlCommand cmd = new SqlCommand("GetLeadsByState", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
dt = (DataTable)ds.Tables[0];
JSONString = JsonConvert.SerializeObject(dt, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
Formatting = Formatting.Indented
});
}
IEnumerable Data = (from DataRow row in dt.Rows
select new DKDatabaseModelClass.GrossLeadsByStateModel
{
State = row["State"].ToString(),
MailDate = Convert.ToDateTime(row["MailDate"]),
LeadCount = (int)row["LeadCount"]
}).ToList();
Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
Data = operation.PerformSorting(Data, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
Data = operation.PerformWhereFilter(Data, dm.Where, dm.Where[0].Operator);
}
count = Data.AsQueryable().Count();
if (dm.Skip != 0)
{
Data = operation.PerformSkip(Data, dm.Skip);
}
if (dm.Take != 0)
{
Data = operation.PerformTake(Data, dm.Take);
}
return Json(new { result = Data, count = count }, JsonRequestBehavior.AllowGet);
}
Thanks for your help.
SIGN IN To post a reply.
5 Replies
SA
Saravanan Arunachalam
Syncfusion Team
November 3, 2017 07:30 AM UTC
Hi Richard,
Thanks for contacting Syncfusion’s support.
We have analyzed your query, the cause of the issue is that you have not handle the aggregation on server side and we have already discussed this query in the following UG documentation link.
Regards,
Saravanan A.
RD
Richard Dublon
November 16, 2017 03:19 PM UTC
Hi,
I was able to get the summary column to work but it doesn't update when I filter the grid.
Here is my view code:
@(Html.EJ().Grid<object>("StateGrid")
.ToolbarSettings(toolBar => toolBar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.ExcelExport);
}))
.Mappers(map => map.ExportToExcelAction("ExportStateGrid"))
.ClientSideEvents(events => events.Load("onLoad").DataBound("dataBound"))
.Datasource(ds => ds.URL(@Url.Action("LeadsByState"))
.Adaptor(AdaptorType.UrlAdaptor))
.AllowPaging()
.AllowSorting()
.AllowFiltering()
.FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
.EnableAltRow()
.ShowSummary()
.SummaryRow(row =>
{
row.Title("Count").SummaryColumns(col => { col.SummaryType(SummaryType.Sum).DisplayColumn("LeadCount").DataMember("LeadCount").Add(); }).Add();
})
.Columns(col =>
{
col.Field("State").HeaderText("State").Add();
col.Field("MailDate").HeaderText("Mail Date").Format("{0:M/d/yyyy}").Add();
col.Field("LeadCount").HeaderText("Lead Count").Add();
})
.ClientSideEvents(eve => { eve.RowSelected("rowSelected"); })
)
Here is my controller code:
DataResult result = new DataResult();
DataTable dtResult = new DataTable();
int count = 0;
dtResult = GetGridData("spGetLeadsByState");
IEnumerable Data = (from DataRow row in dtResult.Rows
select new DKDatabaseModelClass.GrossLeadsByStateModel
{
State = row["State"].ToString(),
MailDate = Convert.ToDateTime(row["MailDate"]),
LeadCount = (int)row["LeadCount"]
}).ToList();
Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();
List<string> aggregateFields = new List<string>();
if (dm.Aggregates != null)
{
for (var i = 0; i < dm.Aggregates.Count; i++)
aggregateFields.Add(dm.Aggregates[i].Field);
result.aggregate = operation.PerformSelect(Data, aggregateFields);
}
if (dm.Search != null)
Data = operation.PerformSearching(Data, dm.Search);
if (dm.Where != null)
Data = operation.PerformWhereFilter(Data, dm.Where, dm.Where[0].Condition);
result.count = Data.AsQueryable().Count();
if (dm.Skip != null && dm.Skip != 0)//skiped while rendering checkbox
Data = operation.PerformSkip(Data, dm.Skip);
if (dm.Take != null && dm.Take != 0)//skiped while rendering checkbox
Data = operation.PerformTake(Data, dm.Take);
result.result = Data;//passed the whole dataSource directly for checkbox rendering
return Json(result, JsonRequestBehavior.AllowGet);
MS
Mani Sankar Durai
Syncfusion Team
November 17, 2017 11:43 AM UTC
Hi Richard,
We have checked your code example and we are able to reproduce the reported issue. Since you are performing server side filtering operation after the aggregation. So while handling aggregation before filtering it will retrieve the result based on all data. To avoid the issue we suggest you to handling aggregation based on filtered record instead of whole data (set the aggregation code after performing filtering).
Please refer the code example
|
public ActionResult UrlDataSource(DataManager dm)
{
IEnumerable Data = new NorthwindDataContext().OrdersViews.ToList();
DataResult result = new DataResult();
Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();
List<string> aggregateFields = new List<string>();
if (dm.Search != null)
Data = operation.PerformSearching(Data, dm.Search);
if (dm.Where != null)
Data = operation.PerformWhereFilter(Data, dm.Where, dm.Where[0].Condition); //perform filtering
if (dm.Aggregates != null)
{
for (var i = 0; i < dm.Aggregates.Count; i++)
aggregateFields.Add(dm.Aggregates[i].Field);
result.aggregate = operation.PerformSelect(Data, aggregateFields);
} //perform aggregation.
result.count = Data.AsQueryable().Count();
if (dm.Skip != null && dm.Skip != 0)//skiped while rendering checkbox
Data = operation.PerformSkip(Data, dm.Skip);
if (dm.Take != null && dm.Take != 0)//skiped while rendering checkbox
Data = operation.PerformTake(Data, dm.Take);
result.result = Data;//passed the whole dataSource directly for checkbox rendering
return Json(result, JsonRequestBehavior.AllowGet);
}
|
Refer the online sample link
Please let us know if you need further assistance.
Regards,
Manisankar Durai.
Hi Richard,
We have checked your code example and we are able to reproduce the reported issue. Since you are performing server side filtering operation after the aggregation. So while handling aggregation before filtering it will retrieve the result based on all data. To avoid the issue we suggest you to handling aggregation based on filtered record instead of whole data (set the aggregation code after performing filtering).Please refer the code example
public ActionResult UrlDataSource(DataManager dm){IEnumerable Data = new NorthwindDataContext().OrdersViews.ToList();DataResult result = new DataResult();Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();List<string> aggregateFields = new List<string>();if (dm.Search != null)Data = operation.PerformSearching(Data, dm.Search);if (dm.Where != null)Data = operation.PerformWhereFilter(Data, dm.Where, dm.Where[0].Condition); //perform filteringif (dm.Aggregates != null){for (var i = 0; i < dm.Aggregates.Count; i++)aggregateFields.Add(dm.Aggregates[i].Field);result.aggregate = operation.PerformSelect(Data, aggregateFields);} //perform aggregation.result.count = Data.AsQueryable().Count();if (dm.Skip != null && dm.Skip != 0)//skiped while rendering checkboxData = operation.PerformSkip(Data, dm.Skip);if (dm.Take != null && dm.Take != 0)//skiped while rendering checkboxData = operation.PerformTake(Data, dm.Take);result.result = Data;//passed the whole dataSource directly for checkbox renderingreturn Json(result, JsonRequestBehavior.AllowGet);}
Refer the online sample link
Please let us know if you need further assistance.
Regards,Manisankar Durai.
Hi sir,
I used the code for server side aggregation just like the one you provided
if (dm.Where != null)
Data = operation.PerformWhereFilter(Data, dm.Where, dm.Where[0].Condition); //perform filtering
if (dm.Aggregates != null)
{
for (var i = 0; i < dm.Aggregates.Count; i++)
aggregateFields.Add(dm.Aggregates[i].Field);
result.aggregate = operation.PerformSelect(Data, aggregateFields);
} //perform aggregation.
but this thing returned very large amount of data back to the client, it selected the aggregate field on each entries...
this is the result passed back from the controller to the browser
- {,…}
- aggregate:[{TotalAmount: 3159800}, {TotalAmount: 916300}, {TotalAmount: 2054400}, {TotalAmount: 1850000},…]
- [0 … 99]
- 0:{TotalAmount: 3159800}
- 1:{TotalAmount: 916300}
- 2:{TotalAmount: 2054400}
- 3:{TotalAmount: 1850000}
- 4:{TotalAmount: 5794200}
- 5:{TotalAmount: 1683500}
- 6:{TotalAmount: 296000}
- 7:{TotalAmount: 6040000}
- 8:{TotalAmount: 2250000}
- 9:{TotalAmount: 2625000}
- 10:{TotalAmount: 29772150}
- 11:{TotalAmount: 3360000}
- 12:{TotalAmount: 2294000}
- 13:{TotalAmount: 902000}
- 14:{TotalAmount: 1056000}
- 15:{TotalAmount: 798000}
- 16:{TotalAmount: 11312320}
- 17:{TotalAmount: 4345200}
- 18:{TotalAmount: 1343000}
- 19:{TotalAmount: 9700000}
- 20:{TotalAmount: 2752000}
- 21:{TotalAmount: 1150000}
- 22:{TotalAmount: 19600000}
- 23:{TotalAmount: 6612900}
- 24:{TotalAmount: 0}
- 25:{TotalAmount: 0}
- 26:{TotalAmount: 7896000}
- 27:{TotalAmount: 577600}
- 28:{TotalAmount: 3700000}
- 29:{TotalAmount: 4200000}
- 30:{TotalAmount: 52500000}
- 31:{TotalAmount: 588000}
- 32:{TotalAmount: 23058400}
- 33:{TotalAmount: 1410000}
- 34:{TotalAmount: 12680000}
- 35:{TotalAmount: 3850000}
- 36:{TotalAmount: 3666000}
- 37:{TotalAmount: 3650000}
- 38:{TotalAmount: 5327600}
- 39:{TotalAmount: 19900000}
- 40:{TotalAmount: 1110000}
- 41:{TotalAmount: 4526000}
- 42:{TotalAmount: 8640000}
- 43:{TotalAmount: 2500000}
- 44:{TotalAmount: 4200000}
- 45:{TotalAmount: 2016000}
- 46:{TotalAmount: 966000}
- 47:{TotalAmount: 7140000}
- 48:{TotalAmount: 2816000}
- 49:{TotalAmount: 2856000}
- 50:{TotalAmount: 6279000}
- 51:{TotalAmount: 893760}
- 52:{TotalAmount: 294000}
- 53:{TotalAmount: 12807500}
- 54:{TotalAmount: 14926800}
- 55:{TotalAmount: 3240000}
- 56:{TotalAmount: 3290000}
- 57:{TotalAmount: 15540000}
- 58:{TotalAmount: 666000}
- 59:{TotalAmount: 12468100}
- 60:{TotalAmount: 6764000}
- 61:{TotalAmount: 580500}
- 62:{TotalAmount: 11450000}
- 63:{TotalAmount: 1596000}
- 64:{TotalAmount: 196000}
- 65:{TotalAmount: 1017500}
- 66:{TotalAmount: 17475000}
- 67:{TotalAmount: 2508000}
- 68:{TotalAmount: 400000}
- 69:{TotalAmount: 10819400}
- 70:{TotalAmount: 704000}
- 71:{TotalAmount: 13036400}
- 72:{TotalAmount: 1998000}
- 73:{TotalAmount: 7150000}
- 74:{TotalAmount: 3132000}
- 75:{TotalAmount: 20160000}
- 76:{TotalAmount: 199750}
- 77:{TotalAmount: 1680000}
- 78:{TotalAmount: 1865500}
- 79:{TotalAmount: 4149900}
- 80:{TotalAmount: 2290000}
- 81:{TotalAmount: 1096500}
- 82:{TotalAmount: 15870000}
- 83:{TotalAmount: 5838000}
- 84:{TotalAmount: 13463200}
- 85:{TotalAmount: 8492500}
- 86:{TotalAmount: 540000}
- 87:{TotalAmount: 17020200}
- 88:{TotalAmount: 298200}
- 89:{TotalAmount: 5676000}
- 90:{TotalAmount: 249000}
- 91:{TotalAmount: 12025000}
- 92:{TotalAmount: 1900000}
- 93:{TotalAmount: 967200}
- 94:{TotalAmount: 0}
- 95:{TotalAmount: 15190000}
- 96:{TotalAmount: 3840000}
- 97:{TotalAmount: 209400}
- 98:{TotalAmount: 1664000}
- 99:{TotalAmount: 4680000}
- [100 … 199]
- [200 … 299]
- [300 … 399]
- [400 … 499]
- [500 … 599]
- [600 … 699]
- [700 … 799]
- [800 … 899]
- [900 … 999]
- [1000 … 1099]
- [1100 … 1199]
- [1200 … 1299]
- [1300 … 1399]
- [1400 … 1499]
- [1500 … 1599]
- [1600 … 1699]
- [1700 … 1799]
- [1800 … 1899]
- [1900 … 1999]
- [2000 … 2099]
- [2100 … 2199]
- [2200 … 2299]
- [2300 … 2399]
- [2400 … 2499]
- [2500 … 2599]
- [2600 … 2699]
- [2700 … 2799]
- [2800 … 2899]
- [2900 … 2999]
- [3000 … 3099]
- [3100 … 3199]
- [3200 … 3299]
- [3300 … 3399]
- [3400 … 3499]
- [3500 … 3599]
- [3600 … 3699]
- [3700 … 3799]
- [3800 … 3899]
- [3900 … 3999]
- [4000 … 4099]
- [4100 … 4199]
- [4200 … 4299]
- [4300 … 4399]
- [4400 … 4499]
- [4500 … 4599]
- [4600 … 4699]
- [4700 … 4799]
- [4800 … 4899]
- [4900 … 4999]
- [5000 … 5099]
- [5100 … 5199]
- [5200 … 5299]
- [5300 … 5399]
- [5400 … 5499]
- [5500 … 5599]
- [5600 … 5699]
- [5700 … 5799]
- [5800 … 5899]
- [5900 … 5999]
- [6000 … 6099]
- [6100 … 6199]
- [6200 … 6299]
- [6300 … 6399]
- [6400 … 6423]
- count:6424
- groupDs:null
- result:[{ID: 8785, OrderNumber: "GBM/SO/032918/0054", SalesUsername: "",…},…]
this obviously caused the query to slow down.. it went up to 1.5~2.5s with 6400 records which is really not practical
is there anyway to simply do the SUM in the server side instead of selecting the value like this?
something like
result.aggregate = operation.PerformSum(Data, aggregateFields);
Thanks
FS
Farveen Sulthana Thameeztheen Basha
Syncfusion Team
April 2, 2018 04:50 PM UTC
Hi Andrias,
If you want to get the Totalvalue of the summary column, you need to return the value from the serverside as like the above code example and link:-
Please get back to us if you need any further assistance.
Regards,
Farveen sulthana T
SIGN IN To post a reply.
- 5 Replies
- 5 Participants
-
RD Richard Dublon
- Nov 2, 2017 02:38 PM UTC
- Apr 2, 2018 04:50 PM UTC