|
| 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