We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridTemplateColumn header width


I use GridTemplateColumn in SfDataGrid.
ColumnSizer property of the grid sets to Auto.
When I set HeaderText property of the column to some value ("*" on the screenshot below) column header width looks good.
But if I remove HeaderText property and set HeaderTemplate property of the column to following simple value:

    <TextBlock Text="*" />

column header width becomes too large.

Please see screenshot:

How I can fix column header width in case of HeaderTemplate?


3 Replies

AS Ambarish Srinivasan Syncfusion Team January 29, 2016 11:47 AM UTC

Hi Vladimir,

The Width of a column header will be calculated based on the MappingName and HeaderText of a column. In you case, width calculate based on MappingName. To overcome this problem either set Width or HeaderText property. If you set HeaderText property, then width will be calculated based on HeaderText property instead of MappingName.  


<DataTemplate x:Key="Header">

            <TextBlock Text="*" />

<syncfusion:GridTemplateColumn Width="30"

                               HeaderTemplate="{StaticResource Header}"
                               MappingName="OrderID" />


VF vfilatov January 29, 2016 12:39 PM UTC

Yes, it seems that the width of the column header depends of MappingName. I think that a little strange, because I don't use MappingName in my HeaderTemplate in any way.
I don't want to set column width directly because column data is dynamic and width of data if variable. ColumnSizer="Auto" is the best choice for this case but (I think) algorithm should calculate HeaderTemplate width (after render it for real data) and sets width of the column accordingly.
In any case, thanks for beautiful DataGrid.

AS Ambarish Srinivasan Syncfusion Team February 1, 2016 12:50 PM UTC

Hi Vladimir,

We have logged the issue report on "Header column width is too large when using HeaderTemplate in GridTemplateColumn" and this issue will be fixed in our upcoming Volume 4 Service pack 1 release which will be available by the mid of February, 2016. 



Live Chat Icon For mobile
Up arrow icon