Reputation: 85
I need to get the sum value of multiple fields, I know how to do one but not sure how to do multiple. What I have is this :
@(Html.Kendo().Grid(Model.Result)
.Name("grid1")
.Columns(col =>
{
col.Bound("Date").Format("{0:n2}").Format("{0:d}");
col.Bound("ClientAge").Format("{0:n2}");
col.Bound("PartnerAge").Format("{0:n2}");
col.Bound("TotalGrossIncome").Format("{0:n2}");
col.Bound("TotalExpenditure").Format("{0:n2}");
col.Bound("TotalNetIncome").Format("{0:n2}");
col.Bound("TotalAssets").Format("{0:n2}");
col.Bound("TotalLiabilities").Format("{0:n2}");
col.Bound("TotalNetAssetValue").Format("{0:n2}");
}
)
.Scrollable()
.Selectable(select => select.Mode(GridSelectionMode.Single))
.DataSource(dataSource => dataSource
.Server()
.Model(model => model.Id(p => p.Date))
).Deferred(true)
)
I basically need the sum value in the footer for following
col.Bound("TotalGrossIncome").Format("{0:n2}");
col.Bound("TotalExpenditure").Format("{0:n2}");
col.Bound("TotalNetIncome").Format("{0:n2}");
col.Bound("TotalAssets").Format("{0:n2}");
col.Bound("TotalLiabilities").Format("{0:n2}");
col.Bound("TotalNetAssetValue").Format("{0:n2}")
Can anyone assist me with this please not a kendo guru yet :(
Upvotes: 1
Views: 9260
Reputation: 85
So I managed to get it sorted :D Have a look below. According to Kendo's Documentation the Template is actually incorrect - using #=sum# is referring to client side as to the initial example for ASP.net. I approached this with a different method and working find now.
@(Html.Kendo().Grid(Model.Result)
.Name("grid1")
.Columns(col =>
{
col.Bound("Date").Format("{0:n2}").Format("{0:d}").FooterTemplate("TOTALS");
col.Bound("ClientAge").Format("{0:n2}");
col.Bound("PartnerAge").Format("{0:n2}");
col.Bound(p => p.TotalGrossIncome).Format("{0:n2}").FooterTemplate(@<text>@item.Sum.Format("{0:c}")</text>);
col.Bound(p => p.TotalExpenditure).Format("{0:n2}").FooterTemplate(@<text>@item.Sum.Format("{0:c}")</text>);
col.Bound(p => p.TotalNetIncome).Format("{0:n2}").FooterTemplate(@<text>@item.Sum.Format("{0:c}")</text>);
col.Bound(p => p.TotalAssets).Format("{0:n2}").FooterTemplate(@<text>@item.Sum.Format("{0:c}")</text>);
col.Bound(p => p.TotalLiabilities).Format("{0:n2}").FooterTemplate(@<text>@item.Sum.Format("{0:c}")</text>);
col.Bound(p => p.TotalNetAssetValue).Format("{0:c}").FooterTemplate(@<text>@item.Sum.Format("{0:c}")</text>);
})
.Pageable()
.Selectable(select => select.Mode(GridSelectionMode.Single))
.DataSource(dataSource => dataSource
.Server()
.Model(model => model.Id(p => p.Date))
.PageSize(100)
.Aggregates(aggregates =>
{
aggregates.Add(p => p.TotalGrossIncome).Sum();
aggregates.Add(p => p.TotalExpenditure).Sum();
aggregates.Add(p => p.TotalNetIncome).Sum();
aggregates.Add(p => p.TotalAssets).Sum();
aggregates.Add(p => p.TotalLiabilities).Sum();
aggregates.Add(p => p.TotalNetAssetValue).Sum();
})
)
.Deferred(true)
)
Upvotes: 4