How to change the column template icon color based on condition in Blazor DataGrid?

Answer:

We can change the color of the icons using style tag for span element. Inside the Column template an condition is used to check the value of EmployeeID to change the icons color. Refer the below code example.

<SfGrid DataSource="@Employees">

<GridColumns>

<GridColumn HeaderText="Change" TextAlign="TextAlign.Left" Width="50">

<Template>

@{

var val = (context as EmployeeData);

if (val.EmployeeID > 4)

{

<span class="e-icons e-arrow" style="color:red" data-icon="bx:bxs-error-alt" data-inline="false">span>

}

else

{

<span class="e-icons e-arrow" style="color:blue" data-icon="bx:bxs-error-alt" data-inline="false">span>

}

}

Template>

GridColumn>

. . .. .

GridColumns>

SfGrid>


Find the sample for changing the color of the icons based on conditions here.

Here is the UG documentation for your reference.


Loader.
Up arrow icon