|
| 1 | +--- |
| 2 | +title: Templates |
| 3 | +page_title: MultiColumnComboBox Column Templates |
| 4 | +description: Column Templates in MultiColumnComboBox for Blazor. |
| 5 | +slug: multicolumncombobox-templates |
| 6 | +tags: telerik,blazor,multicolumncombobox,combo,columns,headertemplate,celltemplate,templates |
| 7 | +published: True |
| 8 | +position: 10 |
| 9 | +--- |
| 10 | + |
| 11 | + |
| 12 | +# MultiColumnComboBox Column Templates |
| 13 | + |
| 14 | +This article explains the available templates for the Columns of the MultiColumnComboBox for Blazor. |
| 15 | + |
| 16 | +<style> |
| 17 | + article style + table { |
| 18 | + table-layout: auto; |
| 19 | + word-break: normal; |
| 20 | + } |
| 21 | +</style> |
| 22 | +| Template | Description |
| 23 | +| ----------- | ----------- | -----------| |
| 24 | +| [`HeaderTemplate`](#headertemplate) | The HeaderTemplate allows you to control the rendering of the column's header cell. | |
| 25 | +| [`Template`](#template) | The Template allows you to control the rendering of the column's cells. | |
| 26 | + |
| 27 | + |
| 28 | +## HeaderTemplate |
| 29 | + |
| 30 | +The `HeaderTemplate` allows you to control the rendering of the column's header. You can define it for each of the columns of the MultiColumnCombobox. |
| 31 | + |
| 32 | +>caption Use the HeaderTemplate to add an icon to the header cells |
| 33 | +
|
| 34 | +````CSHTML |
| 35 | +<TelerikMultiColumnComboBox Data="@MultiComboData" |
| 36 | + @bind-Value="@BoundValue" |
| 37 | + ValueField="@nameof(SampleData.Id)" |
| 38 | + TextField="@nameof(SampleData.Name)" |
| 39 | + Width="300px"> |
| 40 | + <MultiColumnComboBoxColumns> |
| 41 | + <MultiColumnComboBoxColumn Field="@nameof(SampleData.Id)"> |
| 42 | + <HeaderTemplate> |
| 43 | + <TelerikIcon Icon="info-circle"></TelerikIcon> |
| 44 | + Unique identifier |
| 45 | + </HeaderTemplate> |
| 46 | + </MultiColumnComboBoxColumn> |
| 47 | + <MultiColumnComboBoxColumn Field="@nameof(SampleData.Name)"> |
| 48 | + <HeaderTemplate> |
| 49 | + <TelerikIcon Icon="star-outline"></TelerikIcon> |
| 50 | + Employee Name |
| 51 | + </HeaderTemplate> |
| 52 | + </MultiColumnComboBoxColumn> |
| 53 | + </MultiColumnComboBoxColumns> |
| 54 | +</TelerikMultiColumnComboBox> |
| 55 | +
|
| 56 | +@code { |
| 57 | + public int BoundValue { get; set; } |
| 58 | +
|
| 59 | + public List<SampleData> MultiComboData { get; set; } = Enumerable.Range(0, 30).Select(x => new SampleData() |
| 60 | + { |
| 61 | + Id = x, |
| 62 | + Name = "Name " + x |
| 63 | + }).ToList(); |
| 64 | +
|
| 65 | + public class SampleData |
| 66 | + { |
| 67 | + public int Id { get; set; } |
| 68 | + public string Name { get; set; } |
| 69 | + } |
| 70 | +} |
| 71 | +```` |
| 72 | + |
| 73 | +## Template |
| 74 | + |
| 75 | +The `Template` (Cell Template) allows you to control the rendering of the cells in the MultiComboBoxColumn. You can access the `context` object and cast it to the bound model to employ some custom business logic. The `contenxt` represents the current data item in the cell. |
| 76 | + |
| 77 | +>caption Use the Template to visually distinguish some Ids |
| 78 | +
|
| 79 | +````CSHTML |
| 80 | +<TelerikMultiColumnComboBox Data="@MultiComboData" |
| 81 | + @bind-Value="@BoundValue" |
| 82 | + ValueField="@nameof(SampleData.Id)" |
| 83 | + TextField="@nameof(SampleData.Name)" |
| 84 | + Width="300px"> |
| 85 | + <MultiColumnComboBoxColumns> |
| 86 | + <MultiColumnComboBoxColumn Field="@nameof(SampleData.Id)"> |
| 87 | + <Template> |
| 88 | + @{ |
| 89 | + var currentEmployee = context as SampleData; |
| 90 | +
|
| 91 | + @if(currentEmployee.Id % 3 == 0) |
| 92 | + { |
| 93 | + <span style="font-weight:bold">Important id: @currentEmployee.Id</span> |
| 94 | + } |
| 95 | + else |
| 96 | + { |
| 97 | + <span style="font-style:italic">@currentEmployee.Id</span> |
| 98 | + } |
| 99 | + } |
| 100 | + </Template> |
| 101 | + </MultiColumnComboBoxColumn> |
| 102 | + <MultiColumnComboBoxColumn Field="@nameof(SampleData.Name)"> |
| 103 | + </MultiColumnComboBoxColumn> |
| 104 | + </MultiColumnComboBoxColumns> |
| 105 | +</TelerikMultiColumnComboBox> |
| 106 | +
|
| 107 | +@code { |
| 108 | + public int BoundValue { get; set; } |
| 109 | +
|
| 110 | + public List<SampleData> MultiComboData { get; set; } = Enumerable.Range(0, 30).Select(x => new SampleData() |
| 111 | + { |
| 112 | + Id = x, |
| 113 | + Name = "Name " + x |
| 114 | + }).ToList(); |
| 115 | +
|
| 116 | + public class SampleData |
| 117 | + { |
| 118 | + public int Id { get; set; } |
| 119 | + public string Name { get; set; } |
| 120 | + } |
| 121 | +} |
| 122 | +```` |
0 commit comments