I have a nested grid and would like to change the colors of certain header cells based on the values in other header cells. I tried using the HeaderCellInfo event but it doesn't fire for some reason. How would a go about doing this?
The same concept works fine for QueryCellInfo event for non-header cells.
Thanks
|
@page "/"
@using Syncfusion.Blazor.Grids
<SfGrid DataSource="@Orders" Height="315">
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" CustomAttributes="@(new Dictionary<string, object>(){ { "class", "e-attr1" }})" TextAlign="TextAlign.Right" Width="140"></GridColumn>
<GridColumn Field=@nameof(Order.ShipCity) HeaderText="Ship City" CustomAttributes="@(new Dictionary<string, object>(){ { "class", "e-attr2" }})" Width="100"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" Width="100"></GridColumn>
</GridColumns>
</SfGrid>
<style>
.e-headercell.e-attr1 {
background: #d7f0f4;
}
.e-headercell.e-attr2 {
background: red;
}
</style> |
Not exactly :) I have GridAggregateColumns with GroupCaptionTemplates and I want to change the background color based on the values in other GridAggregateColumns in the grid. GridAggregateColumn doesn't seem to have a CustomAttributes.
<GridAggregateColumn Field="@nameof(Overall2.HoursAdherence)" Type="AggregateType.Average" >
<GroupCaptionTemplate Context="subContext">
@{
var aggregate = CalculateAggregateHours(subContext as AggregateTemplateContext);
<span>@aggregate%</span>
}
</GroupCaptionTemplate>
</GridAggregateColumn>
<GridAggregateColumn Field="@nameof(Overall2.ShiftAdherence)" Type="AggregateType.Average" >
<GroupCaptionTemplate Context="subContext">
@{
var aggregate = CalculateAggregateShift(subContext as AggregateTemplateContext);
<span>@aggregate%</span>
}
</GroupCaptionTemplate>
|
<SfGrid DataSource="@Products" AllowGrouping="true" AllowPaging="true">
<GridGroupSettings Columns=@Units></GridGroupSettings>
<GridAggregates>
<GridAggregate>
<GridAggregateColumns>
<GroupCaptionTemplate>
@{
var aggregate = ((context as AggregateTemplateContext).Max);
int aggregate1 = Convert.ToInt32(aggregate);
if (aggregate1 >= 10)
{
<div class="e-summarycell" style="background-color:green">
Maximum: @aggregate
</div>
}
else
{
<div class="e-summarycell" style="background-color:red">
Maximum: @aggregate
</div>
}
}
</GroupCaptionTemplate>
</GridAggregateColumn>
</GridAggregateColumns>
</GridAggregate>
</GridAggregates>
<GridColumns>
<GridColumn Field=@nameof(Product.ProductName) HeaderText="Product Name" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Product.QuantityPerUnit) HeaderText="Quantity Per Unit" Width="150"></GridColumn>
<GridColumn Field=@nameof(Product.UnitsInStock) HeaderText="Units In Stock" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Product.Discontinued) HeaderText="Discontinued" TextAlign="TextAlign.Right" DisplayAsCheckBox="true" Type="ColumnType.Boolean"></GridColumn>
</GridColumns>
</SfGrid>
|