I'm having some issues with pivot grid and need some assistance.
I'm trying to create a pivot grid that looks something like this. It's a simple example that I would be expanding on. It shows the total commission received from a company by year.
I've two questions:
- 1) Can I get the data directly from the SQL Table without going into a list
- 2) Why is nothing showing up in the pivot grid
Right now I'm testing in Asp.Net Core .Net 6 and Telerik.UI.for.AspNet.Core 2022.1.301
The model looks like this
public class CommRecd
{
public Guid Id { get; set; }
public DateTime ReceivedDate { get; set; }
public string? CompanyName { get; set; }
public Decimal ReceivedAmount { get; set; }
public int ReceivedYear { get; set; }
}
The controller method is below and I've confirmed that objCommList contains the data
public IActionResult PivotGrid()
{
IEnumerable<CommRecd> objCommList = _db.CommRecd;
return View(objCommList);
}
I'm basing my code on this example Remote binding in ASP.NET Core PivotGrid Component Demo | Telerik UI for ASP.NET Core with the code shown below.
@using Application.Models;
@model IEnumerable<CommRecd>
@{ ViewBag.Title = "Commission Received Report"; }
@Html.AntiForgeryToken()
<div class="k-pivotgrid-wrapper">
@(Html.Kendo().PivotConfigurator()
.Name("configurator")
.HtmlAttributes(new { @class = "hidden-on-narrow" })
.Filterable(true)
.Sortable(true)
.Height(570)
)
@(Html.Kendo().PivotGrid<CommRecd>()
.Name("pivotgrid")
.Configurator("#configurator")
.ColumnWidth(120)
.Filterable(true)
.Height(570)
.DataSource(dataSource => dataSource
.Ajax()
.Schema(schema => schema
.Cube(cube => cube
.Dimensions(dimensions => {
dimensions.Add(model => model.CompanyName).Caption("All Companies");
dimensions.Add(model => model.ReceivedAmount).Caption("All Amounts");
dimensions.Add(model => model.ReceivedYear).Caption("All Years");
})
.Measures(measures =>
{
measures.Add("Sum").Format("{0:c}").Field(model => model.ReceivedAmount).AggregateName("sum");
})
))
.Columns(columns =>
{
columns.Add("ReceivedDate").Expand(true);
})
.Rows(rows => rows.Add("CompanyName").Expand(true))
.Measures(measures => measures.Values("Sum"))
.Events(e => e.Error("onError"))
)
)
</div>
<div class="responsive-message"></div>
<script>
function onError(e) {
alert("error: " + kendo.stringify(e.errors[0]));
}
</script>
My output looks like this
Thanks for any suggestions