Skip to content

Commit f24e8b1

Browse files
author
KB Bot
committed
Added new kb article grid-dynamically-adjusting-column-header-styles
1 parent 7cba97f commit f24e8b1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Dynamically Adjusting Column Header Cell Style in Blazor Grid
3+
description: Learn how to dynamically change the style of a column header cell in a Telerik Blazor Grid based on condition.
4+
type: how-to
5+
page_title: How to Dynamically Style Column Header Cell in a Telerik Blazor Grid
6+
slug: grid-dynamically-adjusting-column-header-styles
7+
tags: grid, blazor, header, headerclass
8+
res_type: kb
9+
ticketid: 1670074
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product</td>
18+
<td>Grid for Blazor</td>
19+
</tr>
20+
</tbody>
21+
</table>
22+
23+
## Description
24+
25+
I am dynamically creating Grid columns in a loop and trying to adjust the column header cell style based on some condition and value from the [column field]({%slug components/grid/columns/bound%}#data-binding). Ideally, I want to implement logic to make this adjustment based on the value in the header cell. I have not been able to achieve this in the HeaderTemplate tag or in any of the cell render events handlers. In other templates, I have access to the @context field, which would make this easy, but that doesn't seem to work in the HeaderTemplate.
26+
27+
## Solution
28+
29+
To dynamically add style to a column's header cell when dynamically creating columns in a loop, use the [HeaderClass parameter]({%slug components/grid/columns/bound%}#appearance) to set a class under a condition and apply different styles depending on the class. For scenarios with numerous and more complex conditions, create a method to determine the appropriate class.
30+
31+
It's important to note that the [HeaderTemplate]({%slug grid-templates-column-header%}) does not receive a context argument because it is not related to rows and models, as outlined in the [Templates Overview]({%slug components/grid/features/templates%}) of the Telerik UI for Blazor documentation.
32+
33+
### Example
34+
35+
```csharp
36+
37+
```
38+
39+
## See Also
40+
41+
- [Grid HeaderClass Parameter]({%slug components/grid/columns/bound%}#appearance)
42+
- [Grid Column Header Template]({%slug grid-templates-column-header%})
43+
- [Templates Overview - Telerik UI for Blazor]({%slug components/grid/features/templates%})

0 commit comments

Comments
 (0)