@page "/"
<MatTable Items="@cars" class="mat-elevation-z5">
<MatTableHeader>
<th>Name</th>
<th>Price</th>
<th>Horsepower</th>
</MatTableHeader>
<MatTableRow>
<td style="background: @(ConditionalBackground(context));">@context.Name</td>
<td style="background: @(ConditionalBackground(context));">@String.Format("${0:f2}", @context.Price)</td>
<td style="background: @(ConditionalBackground(context));">@context.Horsepower</td>
</MatTableRow>
</MatTable>
@code
{
private static string ConditionalBackground(Car car)
{
return car.Horsepower >= 200 ? "#ff0000" : "#ffffff";
}
public class Car
{
public string Name { get; set; }
public double Price { get; set; }
public int Horsepower { get; set; }
public Car(string name, double price, int horsepower)
{
Name = name;
Price = price;
Horsepower = horsepower;
}
}
Car[] cars = new[]
{
new Car("Volkswagen Golf", 10000, 220),
new Car("Volkswagen Passat", 11000, 240),
new Car("Volkswagen Polo", 12000, 110),
new Car("Ford Focus", 13000, 200),
new Car("Ford Fiesta", 14000, 160),
new Car("Ford Fusion", 15000, 260),
new Car("Ford Mondeo", 16000, 120),
};
}