78 lines
2.2 KiB
Plaintext
78 lines
2.2 KiB
Plaintext
@page "/Box/CheckDDD"
|
|
@using Radzen.Blazor
|
|
@using System.ComponentModel
|
|
|
|
<style>
|
|
|
|
.total-footer {
|
|
font-weight: 600;
|
|
color: var(--rz-secondary);
|
|
padding: 8px 12px;
|
|
background-color: var(--rz-base-100);
|
|
border-top: 2px solid var(--rz-border-default);
|
|
}
|
|
</style>
|
|
@* <RadzenDataGrid @ref="grid" Data="@summaryData" TItem="dynamic"
|
|
AllowPaging="true" PageSize="5">
|
|
<Columns>
|
|
<RadzenDataGridColumn Title="商品品类" Property="Category" Width="200px" />
|
|
<RadzenDataGridColumn Title="销售总量" TextAlign="TextAlign.Right">
|
|
<Template Context="group">
|
|
<span class="font-bold">@group.TotalQuantity.ToString("N0")</span>
|
|
</Template>
|
|
<FooterTemplate>
|
|
<div class="total-footer">
|
|
全品类合计: @orders.Sum(o => o.Quantity).ToString("N0")
|
|
</div>
|
|
</FooterTemplate>
|
|
</RadzenDataGridColumn>
|
|
</Columns>
|
|
</RadzenDataGrid> *@
|
|
|
|
@code {
|
|
RadzenDataGrid<dynamic> grid;
|
|
List<Order> orders = new();
|
|
IEnumerable<dynamic> summaryData;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
// 模拟数据
|
|
orders = new List<Order> {
|
|
new Order { Category = "电子产品", Quantity = 15 },
|
|
new Order { Category = "电子产品", Quantity = 8 },
|
|
new Order { Category = "家居用品", Quantity = 23 }
|
|
};
|
|
|
|
CalculateSummary();
|
|
}
|
|
|
|
void CalculateSummary()
|
|
{
|
|
summaryData = orders
|
|
.GroupBy(o => o.Category)
|
|
.Select(g => new
|
|
{
|
|
Category = g.Key,
|
|
TotalQuantity = g.Sum(x => x.Quantity)
|
|
}).ToList();
|
|
}
|
|
|
|
public class Order : INotifyPropertyChanged
|
|
{
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
public string Category { get; set; }
|
|
private int _quantity;
|
|
public int Quantity
|
|
{
|
|
get => _quantity;
|
|
set
|
|
{
|
|
_quantity = value;
|
|
PropertyChanged?.Invoke(this,
|
|
new PropertyChangedEventArgs(nameof(Quantity)));
|
|
}
|
|
}
|
|
}
|
|
}
|