@page "/test004"
<PageTitle>測試客製化高階Table元件</PageTitle>
<style>
.yellow-card {
background-color: var(--mud-palette-tertiary) !important;
}
.yellow-card > td {
color: white !important;
}
.yellow-card > td .mud-input {
color: white !important;
}
</style>
<MudContainer MaxWidth=MaxWidth.False>
<HihgOrderTable T=TestProduct DataList=@dataList @bind-CheckedList=@chkList RowClassFunc=YellowRowClassFunc >
<HeaderContent>
<MudThEx For=@(m=>m.ProductNo) />
<MudThEx For=@(m=>m.ProductName) />
<MudThEx For=@(m=>m.Price) />
</HeaderContent>
<RowTemplate>
<MudTd>@context.ProductNo</MudTd>
<MudTd>@context.ProductName</MudTd>
<MudTd>@context.Price</MudTd>
</RowTemplate>
</HihgOrderTable>
</MudContainer>
@* for debug *@
<MudText Inline>
Checked items[@(chkList.Count)]: @(chkList == null ? "" : string.Join(", ", chkList.Select(x => x.ProductNo)))
</MudText>
@code {
// State
List<TestProduct> dataList = new();
HashSet<TestProduct> chkList = new();
protected override void OnInitialized()
{
base.OnInitialized();
// 產生測試資料
for (var i = 0; i < 10; i++)
{
dataList.Add(new TestProduct()
{
ProductNo = (i + 1).ToString(),
ProductName = $"{i + 1}號蘋果",
Price = $"{i + 1}",
LayoutCode = (i % 2 == 0 ? "W1" : "Y1")
});
}
}
string YellowRowClassFunc(TestProduct item, int rowNumber)
{
return item.LayoutCode.StartsWith("Y") ? "yellow-card" : String.Empty;
}
}