Set font color in RowRender/CellRender event

Hello,

is it possible to set the font color for a specific row in RowRender/CellRender event?
(I can set font-weight but not color...)

robert

It is possible to add whatever inline style you want using both RowRender and CellRender and the style will be rendered on the respective HTML element (<tr> or <td>). In the HTML/CSS world however TD will apply the styles on the top of the TR style (you need transparent background for cells to see the row background) and in some cases inline styles will not be able to override the styles defined in the theme CSS depending on the style rule weight. To have full control over row/cell styles you can add additional class to the attributes:



Worked - Thanks a lot!

robert

Hello,

I have done it like that and it works except the RowSelection:

protected void DataGridRowRender(Radzen.RowRenderEventArgs<Models.PDB.Pfuscherakt> args)
{
var fontColorClass = "rz-data-row";

        args.Attributes.Add("style", $"font-weight: {(args.Data.Status == "In Bearbeitung" ? "bold" : "normal")};");

        if (args.Data.Wiedervorlagedatum < DateTime.Today)
        {
            fontColorClass = "cellFontColorRed";
        }

        if (args.Data.Status == "Geschlossen")
        {
            fontColorClass = "cellFontColorGray";
        }
        
        args.Attributes.Add("class", fontColorClass);
    }

it seems that the code in the DataGridRowRender event replaces the class and also then the rz-state-highlight class - how to change the code so that rowseletion is working with it?
(how to append a class not replace existing)

Robert

Hello,

can you give me an advice how to get this working, I mean to have row selection also if I set the class in the DataGridRowRender event?

thanks

This thread might be useful in your case:

I have read this - my problem is the "selection" of the row - how to set the "rz-state-highlight" in the
DataGridRowRender because the selection is set on row/cell click - is there a possibility to get the selected row in the DataGridRowRender event?
I have to now which row is selected to add the class in DataGridRowRender event...

one solution is to set the key in RowSelect to a variable and in the DataGridRowRender event if the values of args.ID == key are the same I set the rz-state-highlight but is this a good solution?

robert

DataGrid selected items can be obtained from the variable used in @bind-Value. Check selection demos.

Thanks it worked in that way

protected void DataGridRowRender(Radzen.RowRenderEventArgs<Models.PDB.Pfuscherakt> args)
        {
            var fontColorClass = "rz-data-row";

            if (selectedPfuscherakt?.FirstOrDefault().Akt_ID == args.Data.Akt_ID)
            {
                fontColorClass += " rz-state-highlight";
            }

            if (args.Data.Wiedervorlagedatum < DateTime.Today)
            {
                fontColorClass += " cellFontColorRed";
            }

            if (args.Data.Status == "Geschlossen")
            {
                fontColorClass += " cellFontColorGray";
            }
            
            args.Attributes.Add("class", fontColorClass);

            args.Attributes.Add("style", $"font-weight: {(args.Data.Status == "In Bearbeitung" ? "bold" : "normal")};");
        }