Skip to content

Commit 79f8c78

Browse files
Add GridCommandColumn HeaderTemplate documentation (#3296)
* Initial plan * Add GridCommandColumn HeaderTemplate documentation Co-authored-by: xristianstefanov <[email protected]> * chore(Grid): polish docs * chore(Grid): add proper meta field --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: xristianstefanov <[email protected]> Co-authored-by: Hristian Stefanov <[email protected]>
1 parent b425131 commit 79f8c78

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

components/grid/columns/command.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ In this article:
2121
* [Built-in Commands](#built-in-commands)
2222
* [OnClick Handler](#the-onclick-handler)
2323
* [Context](#context)
24+
* [Header Template](#header-template)
2425
* [Code Example](#example)
2526

2627
## Features
@@ -91,6 +92,10 @@ Use a **named** context variable to avoid errors when nesting components or `Ren
9192
</GridCommandColumn>
9293
````
9394

95+
### Header Template
96+
97+
The Grid command column supports [`HeaderTemplate`](slug:grid-templates-command-column-header) that allows you to customize the header cell's rendering.
98+
9499
## Example
95100

96101
The following code example demonstrates declarations and handling.

components/grid/templates/column-header.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Bound columns render the name of the field or their `Title` in their header. Thr
8888
8989
![Blazor Grid Header Template](images/header-template.png)
9090

91-
>note Header Templates are not available for the `GridCheckboxColumn` and the `GridCommandColumn`.
91+
>note Header Templates are not available for the `GridCheckboxColumn`.
9292
9393
## See Also
9494

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Command Column Header
3+
meta_title: Grid - Command Column Header Template
4+
description: Use custom command column header template in Grid for Blazor.
5+
slug: grid-templates-command-column-header
6+
tags: telerik,blazor,grid,templates,command,column,header
7+
published: True
8+
position: 23
9+
---
10+
11+
# Command Column Header Template
12+
13+
The `HeaderTemplate` of the Grid command column enables you to customize the header cell's rendering and add custom content or components in the command column header.
14+
15+
>caption Grid Command Column Header Template
16+
17+
````RAZOR
18+
@* Customize the header of the command column *@
19+
20+
<TelerikGrid Data="@GridData"
21+
EditMode="@GridEditMode.Inline"
22+
OnUpdate="@OnUpdateHandler"
23+
Pageable="true"
24+
Height="400px">
25+
<GridColumns>
26+
<GridColumn Field="@nameof(Product.Name)" Title="Product Name" />
27+
<GridColumn Field="@nameof(Product.Price)" Title="Price" />
28+
<GridColumn Field="@nameof(Product.Quantity)" Title="Quantity" />
29+
<GridCommandColumn Width="280px">
30+
<HeaderTemplate>
31+
<TelerikSvgIcon Icon="@SvgIcon.Gear" />
32+
<strong>Actions</strong>
33+
</HeaderTemplate>
34+
<GridCommandButton Command="Edit" Icon="@SvgIcon.Pencil">Edit</GridCommandButton>
35+
<GridCommandButton Command="Save" Icon="@SvgIcon.Save" ShowInEdit="true">Update</GridCommandButton>
36+
<GridCommandButton Command="Cancel" Icon="@SvgIcon.Cancel" ShowInEdit="true">Cancel</GridCommandButton>
37+
<GridCommandButton Command="Delete" Icon="@SvgIcon.Trash">Delete</GridCommandButton>
38+
</GridCommandColumn>
39+
</GridColumns>
40+
</TelerikGrid>
41+
42+
@code {
43+
private List<Product> GridData { get; set; } = new List<Product>();
44+
45+
private async Task OnUpdateHandler(GridCommandEventArgs args)
46+
{
47+
var updatedItem = args.Item as Product;
48+
var index = GridData.FindIndex(p => p.Id == updatedItem.Id);
49+
if (index != -1)
50+
{
51+
GridData[index] = updatedItem;
52+
}
53+
}
54+
55+
protected override void OnInitialized()
56+
{
57+
GridData = Enumerable.Range(1, 10).Select(x => new Product
58+
{
59+
Id = x,
60+
Name = "Product " + x,
61+
Price = Random.Shared.Next(1, 100),
62+
Quantity = Random.Shared.Next(0, 50)
63+
}).ToList();
64+
}
65+
66+
public class Product
67+
{
68+
public int Id { get; set; }
69+
public string Name { get; set; }
70+
public decimal Price { get; set; }
71+
public int Quantity { get; set; }
72+
}
73+
}
74+
````
75+
76+
## See Also
77+
78+
* [Grid Command Column](slug:components/grid/columns/command)

0 commit comments

Comments
 (0)