Column header text alignment.

Currently, if a column is text, the column header text is center aligned.

If the column is numeric, then the header text is right aligned, how can I make the header text centered on a numeric column?


1 Reply 1 reply marked as answer

TP Tamilarasan Paranthaman Syncfusion Team March 15, 2024 01:28 PM UTC

Hi Phunction,

Currently, by default, the header text alignment is set to Start (Left) for DataGridTextColumn and End (Right) for DataGridNumericColumn. You can change the text alignment using the HeaderTextAlignment property in the corresponding column.


We have attached a sample for your reference. In this sample, we have set the HeaderTextAlignment to Center for the DataGridNumericColumn (Order ID). Please review the attached sample and code snippet for more details.


<?xml version="1.0" encoding="utf-8" ?>

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"

             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

             xmlns:local="clr-namespace:MauiApp1"

             xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"

             x:Class="MauiApp1.MainPage">

 

    <ContentPage.BindingContext>

        <local:OrderInfoRepository x:Name="viewModel"/>

    </ContentPage.BindingContext>

 

    <syncfusion:SfDataGrid x:Name="dataGrid"

                           ItemsSource="{Binding OrderInfoCollection}"

                           ColumnWidthMode="Auto"

                           GridLinesVisibility="Both"

                           HeaderGridLinesVisibility="Both"

                           AutoGenerateColumnsMode="None">

        <syncfusion:SfDataGrid.Columns>

            <syncfusion:DataGridNumericColumn MappingName="OrderID"

                                              HeaderTextAlignment="Center"

                                              CellTextAlignment="Center"

                                              HeaderText="Order ID"/>

            <syncfusion:DataGridTextColumn MappingName="CustomerID"

                                           HeaderTextAlignment="Center"

                                           CellTextAlignment="Center"

                                           HeaderText="Customer ID"/>

            <syncfusion:DataGridTextColumn MappingName="Customer"

                                           HeaderText="Customer Name"/>

            <syncfusion:DataGridTextColumn MappingName="ShipCountry"

                                           HeaderText="Ship Country"/>

            <syncfusion:DataGridTextColumn MappingName="ShipCity"

                                           HeaderText="Ship City"/>

            <syncfusion:DataGridNumericColumn MappingName="Price"

                                              HeaderText="Price"/>

        </syncfusion:SfDataGrid.Columns>

    </syncfusion:SfDataGrid>

</ContentPage>

 


UG Documentation: https://help.syncfusion.com/maui/datagrid/column-types#textalignment

We hope this information proves helpful. If there are any misunderstandings regarding your requirements, or if your needs differ in any way, we kindly request that you provide us with more specific and clear details about your use case. This additional information will enable us to thoroughly examine your request and provide an appropriate solution.


Regards,

Tamilarasan


Marked as answer
Loader.
Up arrow icon