PivotGrid

PivotGrid is used to display and aggregate data in a cross-tab format. It allows users to dynamically change the structure of the report by moving fields between rows, columns, and measures.
PivotGrid/Index.cshtml
@(Html.Awex().PivotGrid<Order>(new PivotGridOpt
{
Url = Url.Action("GetOrdersGridData"),
ContentHeight = 300,
})
.Fields(b =>
{
b.Add(o => o.Customer);
b.Add(o => o.Country.Name, new Field { Header = "Country" });
b.Add(o => o.Discount);
b.Add(o => o.Quantity, new Field { CanBeMeasure = true });
b.Add(o => o.UnitPrice, new Field { CanBeMeasure = true, Header = "Price" });
b.Add(o => o.Date);
b.Add(o => o.Delivered);
})
.Rows(b =>
{
b.Add(o => o.Customer);
b.Add(o => o.Date, new Dim { Ext = "Year" });
})
.Columns(b =>
{
b.Add(o => o.Discount);
})
.Measures(b =>
{
b.Add(o => o.Quantity, Agg.Sum);
b.Add(o => o.UnitPrice, Agg.Average);
})
)
Demos/Grid/PivotGridController.cs
public IActionResult GetOrdersGridData(PivotGridParams g)
{
var source = Db.Orders.AsQueryable();

var mb = new PivotGridModelBuilder();

var data = mb.Build(source, g);

return Json(data);
}

Simple Pivot Grid

PivotGrid, smaller demo
PivotGrid/Index.cshtml
@(Html.Awex().PivotGrid<Lunch>(new PivotGridOpt
{
Url = Url.Action("GetLunchGridData", "PivotGrid"),
ContentHeight = 250
})
.Fields(b =>
{
b.Add(o => o.Person);
b.Add(o => o.Dish.Name, new Field { Header = "Dish" });
b.Add(o => o.Country.Name, new Field { Header = "Country" });
b.Add(o => o.Location);
b.Add(o => o.Price);
b.Add(o => new { o.Chef.FirstName, o.Chef.LastName },
new Field { Header = "Chef" });
})
.Rows(b =>
{
b.Add(o => o.Person);
})
.Columns(b =>
{
b.Add(o => new { o.Chef.FirstName, o.Chef.LastName });
})
.Measures(b =>
{
b.Add(o => o.Price, Agg.Average);
})
)
Demos/Grid/PivotGridController.cs
public IActionResult GetLunchGridData(PivotGridParams g)
{
var source = Db.Lunches.AsQueryable();

var mb = new PivotGridModelBuilder();

var data = mb.Build(source, g);

return Json(data);
}



Comments