It is possible to have text wrapping on datagrid column headers ?

Hi,

is it possible to configure a SfDatagrid so that the column headers implement text wrapping?

I'd like, if the user resizes a column header, the related text is wrapped and shown on more lines if the header size is not suitable to show the entire header column text on a single line.
It should be nice the whole header vertical size should automatically change (increase or decreasing) according to the current (wrapped) column header texts.

Is it possible to obtain or implement such a functionality ?

Thank you.

3 Replies

SJ Sathiyathanam Jeyakumar Syncfusion Team April 12, 2018 08:42 PM UTC

Hi Silvio, 
We have prepared the sample based on your requirement. Here you should raise the QueryRowHeight event to change the header row height based on the content present in the cell. And also define the Header template to wrap the text. Please find the below code snippets. 
<Window.Resources> 
        <DataTemplate x:Key="TheHeaderTemplate"> 
            <Grid> 
                <TextBlock                      
                        Text="{Binding}" 
                        TextWrapping="Wrap" /> 
            </Grid> 
        </DataTemplate> 
    </Window.Resources> 
 
<syncfusion:SfDataGrid x:Name="sfdatagrid" 
                               AutoGenerateColumns="False" 
                               ItemsSource="{Binding OrderDetails}" 
                               HeaderTemplate="{StaticResource TheHeaderTemplate}"> 
</syncfusion:SfDataGrid> 
 
private void DataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e) 
{ 
    double height = 0.0; 
    if (dataGrid.GetHeaderIndex() ==e.RowIndex) 
    { 
         bool isAutoRowHeight = dataGrid.GridColumnSizer.GetAutoRowHeight(e.RowIndex, new GridRowSizingOptions(), out height); 
         if (height > dataGrid.RowHeight) 
         { 
              e.Height = height; 
              e.Handled = true; 
          } 
     } 
} 
 
Please find the sample from the below location. 
And also Find the KB link from below location 
Regards, 
Sathiyathanam 



JS James Simons May 6, 2021 12:19 AM UTC

Thank you very much.


MA Mohanram Anbukkarasu Syncfusion Team May 6, 2021 05:04 AM UTC

Hi James, 

Thanks for the update.  

Please let us know if you need any assistance.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon