I need to add class to a row cell based on its value.
Something like:
@inject DataSource Data
<div class="grid">
<QuickGrid Items="@Data.People">
<PropertyColumn Property="@(c => c.PersonId)" Sortable="true" />
<PropertyColumn Property="@(c => c.FirstName)" Sortable="true" />
<PropertyColumn Property="@(c => c.LastName)" Sortable="true" />
<PropertyColumn Property="@(c => c.BirthDate)" Format="yyyy-MM-dd" Sortable="true" Class="@GetClass(context.BirthDate)" />
</QuickGrid>
</div>
@code {
string GetClass(DateOnly birthDate) => birthDate.Year < 2000 ? "table-success" : "table-warning";
}
I am unable to access the item property from within other parameters of PropertyColumn.
I tried to use TemplateColumn, but it only works for the tag within the cell and not the entire cell itself.
<TemplateColumn>
<div class="@GetClass(context.BirthDate)">
@context.ToString("yyyy-MM-dd")
</div>
</TemplateColumn>
This also means that I have to manually handle sorting for the column which was automatically available through PropertyColumn tag.