|
| 1 | +--- |
| 2 | +title: Column Menu |
| 3 | +page_title: Grid - Column Menu |
| 4 | +description: Use the Column Menu for the Grid |
| 5 | +slug: grid-column-menu |
| 6 | +tags: telerik,blazor,grid,column,columns,menu |
| 7 | +published: True |
| 8 | +position: 20 |
| 9 | +--- |
| 10 | + |
| 11 | +# Column Menu |
| 12 | + |
| 13 | +The Grid allows you to setup a menu for it's columns. It enables you to perform high-level customization like [sorting]({%slug components/grid/features/sorting%}), [filtering]({%slug components/grid/filtering%}), [showing or hiding]({%slug grid-columns-visible%}) columns and [freezing or unfreezing]({%slug grid-columns-frozen%}) them. |
| 14 | + |
| 15 | +>caption Telerik Column Menu for the Grid |
| 16 | +
|
| 17 | + |
| 18 | + |
| 19 | +In this article: |
| 20 | +* [Basics](#basics) |
| 21 | +* [Features](#features) |
| 22 | + * [Sorting](#sorting) |
| 23 | + * [Filtering](#filtering) |
| 24 | + * [Frozen Columns](#frozen-columns) |
| 25 | + * [Column Chooser](#column-chooser) |
| 26 | +* [Notes](#notes) |
| 27 | + |
| 28 | +## Basics |
| 29 | + |
| 30 | +To enable the column menu set the `ShowColumnMenu` parameter of the `<TelerikGrid>` tag to `true`. This will enable the menu for each column of the Grid. |
| 31 | + |
| 32 | +To disable the Column Menu for a specific column in the Grid set the `ShowColumnMenu` parameter of the column to `false`. |
| 33 | + |
| 34 | +You can see the what the column menu can do and how to control its settings in the [Features](#features) section. By default, all of them are enabled. |
| 35 | + |
| 36 | +>caption Enable the column menu for all Grid columns. Results in the screnshot above. |
| 37 | +
|
| 38 | +````CSHTML |
| 39 | +@* Set the ShowColumnMenu parameter to true *@ |
| 40 | +
|
| 41 | +<TelerikGrid Data="@MyData" |
| 42 | + Pageable="true" |
| 43 | + PageSize="5" |
| 44 | + FilterMode="@GridFilterMode.FilterMenu" |
| 45 | + Sortable="true" |
| 46 | + ShowColumnMenu="true"> |
| 47 | + <GridColumns> |
| 48 | + <GridColumn Field="@(nameof(SampleData.Id))" Width="80px" /> |
| 49 | + <GridColumn Field="@(nameof(SampleData.Name))" Title="Employee Name" Groupable="false" /> |
| 50 | + <GridColumn Field="@(nameof(SampleData.Team))" Title="Team" /> |
| 51 | + <GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" /> |
| 52 | + </GridColumns> |
| 53 | +</TelerikGrid> |
| 54 | +
|
| 55 | +@code { |
| 56 | + public IEnumerable<SampleData> MyData = Enumerable.Range(1, 30).Select(x => new SampleData |
| 57 | + { |
| 58 | + Id = x, |
| 59 | + Name = "name " + x, |
| 60 | + Team = "team " + x % 5, |
| 61 | + HireDate = DateTime.Now.AddDays(-x).Date |
| 62 | + }); |
| 63 | +
|
| 64 | + public class SampleData |
| 65 | + { |
| 66 | + public int Id { get; set; } |
| 67 | + public string Name { get; set; } |
| 68 | + public string Team { get; set; } |
| 69 | + public DateTime HireDate { get; set; } |
| 70 | + } |
| 71 | +} |
| 72 | +```` |
| 73 | + |
| 74 | +## Features |
| 75 | + |
| 76 | +To control the common features of the `Column Menu` use the `<GridColumnMenuSettings>`, nested inside the `<GridSettings>`: |
| 77 | + |
| 78 | +* [Sorting](#sorting) |
| 79 | +* [Filtering](#filtering) |
| 80 | +* [Frozen Columns](#frozen-columns) |
| 81 | +* [Column Chooser](#column-chooser) |
| 82 | + |
| 83 | +### Sorting |
| 84 | + |
| 85 | +To remove the sorting option from the Column Menu set the `Sortable` parameter of the `GridColumnMenuSettings` tag to `false`. |
| 86 | + |
| 87 | + |
| 88 | +### Filtering |
| 89 | + |
| 90 | +To control whether filtering is possible from the Column Menu set the `FilterMode` parameter of the `GridColumnMenuSettings` tag to a member of the `ColumnMenuFilterMode` enum: |
| 91 | + |
| 92 | +* `None` - disables the filtering from the Column Menu. |
| 93 | +* `FilterMenu` - enables a filter menu to apply filtering. |
| 94 | + |
| 95 | + |
| 96 | +### Frozen Columns |
| 97 | + |
| 98 | +To disable locking and unlocking of a column from the Column Menu, set the `Lockable` parameter of the column to `false`. |
| 99 | + |
| 100 | + |
| 101 | +### Column Chooser |
| 102 | + |
| 103 | +The Column Chooser in the Column Menu and allows you to toggle the visiblity of Grid columns from the Column Menu. By the default all columns are visible under the `Columns` section of the Column Menu (click the Columns item to expand it). |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +To disable the column chooser, set the `ShowColumnChooser` paramter of the `<GridColumnMenuSettings>` to `false`. |
| 108 | + |
| 109 | +To hide a column from the Column Chooser set the `VisibleInColumnChooser` property of the column to `false`. |
| 110 | + |
| 111 | +### Example of Column Menu Features Settings |
| 112 | + |
| 113 | +>caption Use the GridColumnMenuSettings tag to control the common features of the Column Menu, use column parameters to affect its relationship with the column menu |
| 114 | +
|
| 115 | +````CSHTML |
| 116 | +@* Disable filtering and locking columns, hide a column from the chooser (Team), disable the menu for a column (Name). *@ |
| 117 | +
|
| 118 | +<TelerikGrid Data="@MyData" |
| 119 | + Pageable="true" |
| 120 | + PageSize="5" |
| 121 | + FilterMode="@GridFilterMode.FilterMenu" |
| 122 | + Sortable="true" |
| 123 | + ShowColumnMenu="true"> |
| 124 | + <GridSettings> |
| 125 | + <GridColumnMenuSettings Lockable="false" |
| 126 | + FilterMode="@ColumnMenuFilterMode.None"> |
| 127 | + </GridColumnMenuSettings> |
| 128 | + </GridSettings> |
| 129 | + <GridColumns> |
| 130 | + <GridColumn Field="@(nameof(SampleData.Id))" Width="80px" /> |
| 131 | + <GridColumn Field="@(nameof(SampleData.Name))" Title="Employee Name" ShowColumnMenu="false" /> |
| 132 | + <GridColumn Field="@(nameof(SampleData.Team))" Title="Team" VisibleInColumnChooser="false" /> |
| 133 | + <GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" /> |
| 134 | + </GridColumns> |
| 135 | +</TelerikGrid> |
| 136 | +
|
| 137 | +@code { |
| 138 | + public IEnumerable<SampleData> MyData = Enumerable.Range(1, 30).Select(x => new SampleData |
| 139 | + { |
| 140 | + Id = x, |
| 141 | + Name = "name " + x, |
| 142 | + Team = "team " + x % 5, |
| 143 | + HireDate = DateTime.Now.AddDays(-x).Date |
| 144 | + }); |
| 145 | +
|
| 146 | + public class SampleData |
| 147 | + { |
| 148 | + public int Id { get; set; } |
| 149 | + public string Name { get; set; } |
| 150 | + public string Team { get; set; } |
| 151 | + public DateTime HireDate { get; set; } |
| 152 | + } |
| 153 | +} |
| 154 | +```` |
| 155 | + |
| 156 | +>caption Column menu with filtering, locking and sorting, but without a column chooser |
| 157 | +
|
| 158 | + |
| 159 | + |
| 160 | +## Notes |
| 161 | + |
| 162 | +* Applying settings to a Grid column like `Filterable="false"`, `Sortable="false"`, `Lockable="false"` will take precendense over the common settings applied in the `<GridColumnMenuSettings>` and disable the above-mentioned functionalities for the corresponding column. |
| 163 | + |
| 164 | +* An exception will be thrown if the `FilterMode` of the Grid is set to `FilterRow` and a column menu is used - the filter descriptors of the two features are not compatible. |
| 165 | + |
| 166 | +* If the Grid has a [frozen]({%slug grid-columns-frozen%}) column (`Locked="true"`), that column cannot be unfrozen from the column menu. |
| 167 | + |
| 168 | +## See Also |
| 169 | + |
| 170 | + * [Live Demo: Visible Columns](https://demos.telerik.com/blazor-ui/grid/columns) |
0 commit comments