I am using a Grid in an MVC project and it has 2 rows of aggregates. The first row are just the standard Sum aggregates and they work fine but the in the second row I have used the Custom aggregates. The issue is that the template is not being updated on the second row of aggregates and all I see is "%{Custom}" where it sshould show something like "%0.7". One point of interest I should point out is that The exact code pretty much being used in the javascript method MondayAggregateFn is being used in the javascript method
DiscountAggregateFn. It doesnt work on the Monday calculation but it does on the Discount one. They are both in sperate List<Syncfusion.EJ2.Grids.GridAggregateColumn> objects because they need to be on seperate rows but everything on that second row does not work.
@{
List<object> colsSales = new List<object>();
colsSales.Add(new { field = "Location", direction = "Ascending" });
}
@Html.EJS().Grid("EastGrid").Width("90vw").DataSource((IEnumerable<object>)Session["EastWeek"]).AllowExcelExport().ToolbarClick("EastWeekClick").ShowColumnChooser(true).AllowTextWrap().AllowSorting().AllowFiltering(true).Columns(col =>
{
col.Field("Location").HeaderText("Location").CustomAttributes(new { @class = "customblackcss" }).Add();
col.Field("MondaySales").HeaderText("Monday").Format("C2").Add();
col.Field("TuesdaySales").HeaderText("Tuesday").Format("C2").Add();
col.Field("WednesdaySales").HeaderText("Wednesday").Format("C2").Add();
col.Field("ThursdaySales").HeaderText("Thursday").Format("C2").Add();
col.Field("FridaySales").HeaderText("Friday").Format("C2").Add();
col.Field("SaturdaySales").HeaderText("Saturday").Format("C2").Add();
col.Field("SundaySales").HeaderText("Sunday").Format("C2").Add();
col.Field("TotalSales").HeaderText("Totals").Format("C2").CustomAttributes(new { @class = "customblackcss" }).Add();
col.Field("DiscountsAmount").HeaderText("Discounts $").Format("C2").CustomAttributes(new { @class = "customredcss" }).Add();
col.Field("DiscountsPercentage").HeaderText("Discounts %").Format("N1").CustomAttributes(new { @class = "customredcss" }).Add();
}).FilterSettings(filter => { filter.Type(Syncfusion.EJ2.Grids.FilterType.CheckBox); }).Aggregates(agg =>
{
agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() {
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "MondaySales", Format = "C2", Type = "Sum", FooterTemplate = "${Sum}" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "TuesdaySales", Format = "C2", Type = "Sum", FooterTemplate = "${Sum}" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "WednesdaySales", Format = "C2", Type = "Sum", FooterTemplate = "${Sum}" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "ThursdaySales", Format = "C2", Type = "Sum", FooterTemplate = "${Sum}" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "FridaySales", Format = "C2", Type = "Sum", FooterTemplate = "${Sum}" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "SaturdaySales", Format = "C2", Type = "Sum", FooterTemplate = "${Sum}" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "SundaySales", Format = "C2", Type = "Sum", FooterTemplate = "${Sum}" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "TotalSales", Format = "C2", Type = "Sum", FooterTemplate = "${Sum}" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "DiscountsAmount", Format = "C2", Type = "Sum", FooterTemplate = "${Sum}" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "DiscountsPercentage", Type = "Custom", FooterTemplate = "Count:${Custom}", CustomAggregate= "DiscountAggregateFn" }
}).Add();
agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() {
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "MondaySales", Type = "Custom", FooterTemplate = "%{Custom}", CustomAggregate= "MondayAggregateFn" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "TuesdaySales", Type = "Custom", FooterTemplate = "%{Custom}", CustomAggregate= "TuesdayAggregateFn" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "WednesdaySales", Type = "Custom", FooterTemplate = "%{Custom}", CustomAggregate= "WednesdayAggregateFn" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "ThursdaySales", Type = "Custom", FooterTemplate = "%{Custom}", CustomAggregate= "ThursdayAggregateFn" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "FridaySales", Type = "Custom", FooterTemplate = "%{Custom}", CustomAggregate= "FridayAggregateFn" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "SaturdaySales", Type = "Custom", FooterTemplate = "%{Custom}", CustomAggregate= "SaturdayAggregateFn" },
new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "SundaySales", Type = "Custom", FooterTemplate = "%{Custom}", CustomAggregate= "SundayAggregateFn" }
}).Add();
}).Toolbar(new List<string>() { "ColumnChooser", "ExcelExport" }).SortSettings(sort => sort.Columns(colsSales)).Render()
function MondayAggregateFn(data, aggColumn) {
if (data.aggregates && data.aggregates['MondaySales - sum']) {
var part = data.aggregates['MondaySales - sum'];
var total = data.aggregates['TotalSales - sum'];
if (total != 0 || total != null) {
console.log(part);
console.log(total);
var result = (part / total) * 100;
console.log(result);
return result;
} else {
return null;
}
} else {
return null;
}
};
Any help with this would be greatly appreciated.
I would actually like to change the question/bug as I have been testing more and see that if I use the template
FooterTemplate = "Count:${Custom}",
on them it works but I want the template to be:
FooterTemplate = "{Custom}%",
how can this be accomplished?
Thanks
FooterTemplate = "${Custom} %",
Works I must have missed that in the documentation that it needs to lead with the dollar sign,
Hi Nate,
We are glad to hear that you have resolved the reported problem by yourself.
Please get back to us if you need further assistance.
Regards,
Rajapandiyan S