I want conditionally change the text color and background color for all columns of a row.
I was setting the CellRender property and defined in the @code block the following method:
void CellRender(Radzen.CellRenderEventArgs<EventData> args)
{
if (!args.Data.IsAcknowledged)
{
args.Attributes.Add("style", "background-color: red; color: white;");
}
}
On execution, only the background color is changed, but not the text color of the cell.
How can I solve this problem ?
The data grid cell color is set from the CSS theme and takes precedence. You can however style it as in our online demo :
<RadzenGridColumn TItem="OrderDetail" Property="Quantity" Title="Quantity">
<Template Context="data">
@if (data.Quantity > 20)
{
<span style='color:white'>@data.Quantity</span>
}
else
{
<span style='color:black'>@data.Quantity</span>
}
</Template>
</RazenGridColumn>
Thx, I was aware of this, but I want to prevent adding a template for each column
bomner
August 7, 2020, 9:15am
4
args.Attributes.Add("class", "white-text");
td.white-text span.ui-cell-data {
color: white !important;
}
works just fine for color
3 Likes
Adem
February 23, 2022, 9:43am
5
Hi korchev,
When I implemented your solution, I lost the string format. The FormatString value I set on the parent tag doesn't affect the output anymore.
Do you have any solution to this?
This is working though:
enchev
February 23, 2022, 9:47am
6
Hey @Adem ,
In templates you should apply desired format yourself.
1 Like