-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.razor
More file actions
59 lines (51 loc) · 2.54 KB
/
Copy pathIndex.razor
File metadata and controls
59 lines (51 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
@page "/"
@using PivotTableBindToData.Data
@using PivotTableBindToData.Northwind
@using Microsoft.EntityFrameworkCore
@using System.Drawing;
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
@using DevExpress.Blazor.PivotTable
<div>
<DxPivotTable Data="Data">
<Fields>
<DxPivotTableField Field="CategoryName" Area="@PivotTableArea.Row" SummaryType="PivotTableSummaryType.CountDistinct"/>
<DxPivotTableField Field="ProductName" Area="@PivotTableArea.Row" SummaryType="PivotTableSummaryType.CountDistinct"/>
<DxPivotTableField Field="OrderDate" Area="@PivotTableArea.Column" GroupInterval="@PivotTableGroupInterval.DateYear" Caption="Year" />
<DxPivotTableField Field="OrderDate" Area="@PivotTableArea.Column" GroupInterval="@PivotTableGroupInterval.DateQuarter" Caption="Quarter" >
<ValueTemplate>
<span>@($"Q{context.Text}")</span>
</ValueTemplate>
</DxPivotTableField>
<DxPivotTableField Field="UnitPrice" Area="@PivotTableArea.Data" SummaryType="@PivotTableSummaryType.Sum" />
<DxPivotTableField Field="ShipCountry" Area="@PivotTableArea.Filter" SummaryType="PivotTableSummaryType.CountDistinct"/>
<DxPivotTableField Field="ShipCity" Area="@PivotTableArea.Filter" SummaryType="PivotTableSummaryType.CountDistinct" />
</Fields>
</DxPivotTable>
</div>
@code {
NorthwindContext Northwind { get; set; }
IEnumerable<PivotRow> Data { get; set; }
protected override async Task OnInitializedAsync() {
Northwind = NorthwindContextFactory.CreateDbContext();
var products = await Northwind.Products.ToListAsync();
var categories = await Northwind.Categories.ToListAsync();
var orders = await Northwind.Orders.ToListAsync();
var orderDetails = await Northwind.OrderDetails.ToListAsync();
Data = (from c in categories
join p in products on c.CategoryId equals p.CategoryId
join od in orderDetails on p.ProductId equals od.ProductId
select new PivotRow{
CategoryName = c.CategoryName,
ProductName = p.ProductName,
UnitPrice = p.UnitPrice,
OrderDate = od.Order.OrderDate,
ShipCountry = od.Order.ShipCountry,
ShipCity = od.Order.ShipCity
})
.ToList();
}
public void Dispose() {
Northwind?.Dispose();
}
}