@page "/"
<table>
<tr>
<th style="width:50px" />
<th style="width:200px">Region</th>
<th style="width:200px">Sales</th>
</tr>
@foreach (var country in Countries)
{
<tr style="cursor:pointer;" @onclick="()=>country.ShowCities = !country.ShowCities">
@if (!country.ShowCities){
<td>⏵</td>
}
else {
<td>⏷</td>
}
<td >@country.Name</td>
<td>@(AllCitySales.Where(acs=>acs.CountryID==country.ID).Sum(cs=>cs.Sales))</td>
</tr>
if (country.ShowCities)
{
foreach (var city in AllCitySales.Where(acs => acs.CountryID == country.ID))
{
<tr>
<td/>
<td> • @city.Name</td>
<td>@city.Sales</td>
</tr>
}
}
}
</table>
@code {
public class Country
{
public int? ID;
public string? Name;
public bool ShowCities;
}
public class CitySales
{
public int ID;
public int CountryID;
public string? Name;
public int Sales;
}
public List<Country> Countries = new List<Country>
{
new Country{ ID = 1, Name="France"},
new Country{ ID = 2, Name="England"}
};
public List<CitySales> AllCitySales = new List<CitySales>
{
new CitySales{ ID = 1, CountryID = 1, Name="Paris", Sales = 453},
new CitySales{ ID = 2, CountryID = 1, Name="Marseille", Sales = 100},
new CitySales{ ID = 3, CountryID = 2, Name="New York", Sales = 123},
new CitySales{ ID = 4, CountryID = 2, Name="Los Angeles", Sales = 420},
new CitySales{ ID = 5, CountryID = 2, Name="Scranton", Sales = 69}
};
}