|
| 1 | +--- |
| 2 | +title: Column Headers |
| 3 | +page_title: .NET MAUI DataGrid Documentation - Columns Header |
| 4 | +description: Learn how to style and customize the text in the Telerik UI for .NET MAUI DataGrid Header by using the properties of the component. |
| 5 | +position: 2 |
| 6 | +slug: datagrid-column-header |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +# .NET MAUI TreeDataGrid Column Headers |
| 11 | + |
| 12 | +This article will guide you through the usage of the column headers, their customization as well through performing different data operations. Column headers are always visible by default. You can further customize the headers by using the `HeaderStyle` property. |
| 13 | + |
| 14 | +## Changing the Text in the Header |
| 15 | + |
| 16 | +To customize text inside the header, you use the `HeaderText` property. The property is per column. If `HeaderText` is not set, the text inside the `PropertyName` is displayed. |
| 17 | + |
| 18 | +```XAML |
| 19 | +<telerik:RadTreeDataGrid x:Name="dataGrid" |
| 20 | + AutoGenerateColumns="False"> |
| 21 | + <telerik:RadDataGrid.Columns> |
| 22 | + <telerik:DataGridTextColumn PropertyName="Capital" |
| 23 | + HeaderText="Capital Header"/> |
| 24 | + <telerik:DataGridTextColumn PropertyName="Country" |
| 25 | + HeaderText="Country Header"/> |
| 26 | + </telerik:RadDataGrid.Columns> |
| 27 | +</telerik:RadTreeDataGrid> |
| 28 | +``` |
| 29 | + |
| 30 | +## Sorting |
| 31 | + |
| 32 | +The user of the application can sort a particular column by tapping on its header. When the data is sorted by a column, the sort indicator shows in the header. |
| 33 | + |
| 34 | +To learn more about the sorting functionality of the [.NET MAUI TreeDataGrid]({%slug treedatagrid-overview%}), take a look at the [Sorting]({%slug treedatagrid-sorting-overview%}) article. |
| 35 | + |
| 36 | +## Filtering |
| 37 | + |
| 38 | +The header of the column hosts the built-in filtering mechanism (the filter indicator which opens the Filtering UI), which allows the user to filter the data by the columns' values. |
| 39 | + |
| 40 | +To learn more about the filtering functionality, take a look at the [Filtering]({%slug treedatagrid-filtering-overview%}) article. |
| 41 | + |
| 42 | +## Styling |
| 43 | + |
| 44 | +Use the `HeaderStyle` property to style the `DataGridColumn` header. |
| 45 | + |
| 46 | +## Header Content Customization |
| 47 | + |
| 48 | +You can customize the content of the Header using the `HeaderContentTemplate`(`DataTemplate`) property. |
| 49 | + |
| 50 | +To define the `DataTemplate` for the header: |
| 51 | + |
| 52 | +<snippet id='datagrid-headercontenttemplate-datatemplate' /> |
| 53 | + |
| 54 | +## Color on Hover |
| 55 | + |
| 56 | +You can change the hover state background color of the column header by setting the `BackgroundColor` property. |
| 57 | + |
| 58 | +The following example demonstrates how to apply the `BackgroundColor` property to the DataGrid `HeaderContentTemplate` for its hover visual state: |
| 59 | + |
| 60 | +```XAML |
| 61 | +<DataTemplate x:Key="CustomHeaderTemplate"> |
| 62 | + <telerik:RadBorder BackgroundColor="#F8F8F8" |
| 63 | + BorderThickness="1"> |
| 64 | + <VisualStateManager.VisualStateGroups> |
| 65 | + <VisualStateGroup x:Name="CommonStates"> |
| 66 | + <VisualState x:Name="Normal" /> |
| 67 | + <VisualState x:Name="Focused" /> |
| 68 | + <VisualState x:Name="Disabled" /> |
| 69 | + <VisualState x:Name="PointerOver"> |
| 70 | + <VisualState.Setters> |
| 71 | + <Setter Property="BackgroundColor" Value="#33000000" /> |
| 72 | + </VisualState.Setters> |
| 73 | + </VisualState> |
| 74 | + </VisualStateGroup> |
| 75 | + </VisualStateManager.VisualStateGroups> |
| 76 | + </telerik:RadBorder> |
| 77 | +</DataTemplate> |
| 78 | +``` |
| 79 | + |
| 80 | +## Customizing the Column |
| 81 | + |
| 82 | +Customize the column header by using the `HeaderContentTemplate`(of type `DataTemplate`) to achieve the desired full customization of the column. The property demonstrates the ability of the DataGrid to specify and show custom appearance for the column headers. |
| 83 | + |
| 84 | +## See Also |
| 85 | + |
| 86 | +- [Columns Cells Templates]({%slug treedatagrid-cell-templates%}) |
| 87 | +- [Column Footers]({%slug treedatagrid-column-footer%}) |
| 88 | +- [Column Resizing]({%slug treedatagrid-column-resizing%}) |
| 89 | +- [Columns Width]({%slug treedatagrid-columns-width%}) |
| 90 | +- [Frozen Columns]({%slug treedatagrid-frozen-columns%}) |
| 91 | +- [Columns Reordering]({%slug treedatagrid-columns-reordering%}) |
0 commit comments