DataGrid header and cell customisation

There are a few features I'm looking to implement with SfDataGrid in UWP that I'm struggling to implement.
  • Embed the filter button in the header row in a custom header template, instead of having it floating in front of the header template
  • Embed the sort button in the header row in a custom header template, instead of having it floating in front of the header template
  • Turn off text wrapping in grid cells
  • Include an 'id' number (integer) for each entry in the datagrid in the row headers i.e. so these numbers also get filtered/sorted with the rest of the data.
  • Include a checkbox in the row header that sets a boolean property on each item in the datagrid.
Is it possible to achieve any of these?
Thanks in advance!

11 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team December 22, 2020 04:03 PM UTC

Hi Simon, 

Thanks for contacting Syncfusion support.  

Query 
Response 
Embed the filter button in the header row in a custom header template, instead of having it floating in front of the header template 

Embed the sort button in the header row in a custom header template, instead of having it floating in front of the header template 
We are little unclear with these queries. The appearance of sort and filter icons can be customized by editing the style of GridHeaderCellControl. 


Please revert to us with more details about your requirement with image illustration if we have misunderstood your requirement. 
Turn off text wrapping in grid cells 
You can achieve this by setting the TextWrapping property of the columns to NoWrap. 

Include an 'id' number (integer) for each entry in the datagrid in the row headers i.e. so these numbers also get filtered/sorted with the rest of the data. 
You can display the row index values in the row header cells by customizing the style for GridRowHeaderCell as given in the following help documentation.  


But it is not possible to consider filtering and sorting for the row headers. Data operations like filtering, sorting and grouping will be performed based on the mapping name of the columns. So that, it cannot be considered for row headers. There should be a property for the corresponding column in Model class to perform data operations.  
Include a checkbox in the row header that sets a boolean property on each item in the datagrid. 
You can achieve this by customizing the style for GridRowHeaderCell as shown in the following code example.  


Code example :  

<Page.Resources> 
    <local:RowIndexToCheckStateConverter x:Key="RowIndexToCheckStateConverter" /> 
    <Style TargetType="syncfusion:GridRowHeaderCell"> 
        <Setter Property="Template"> 
            <Setter.Value> 
                <ControlTemplate TargetType="syncfusion:GridRowHeaderCell"> 
 
                    <Border x:Name="PART_RowHeaderCellBorder" 
                    BorderBrush="{TemplateBinding BorderBrush}" 
                    BorderThickness="{TemplateBinding BorderThickness}"> 
 
                        <Grid> 
 
                            <CheckBox 
                               IsChecked="{Binding RowIndex, Mode=TwoWay, 
                                              RelativeSource={RelativeSource TemplatedParent}, 
                                Converter={StaticResource RowIndexToCheckStateConverter}}"/> 
 
                        </Grid> 
                    </Border> 
                </ControlTemplate> 
            </Setter.Value> 
        </Setter> 
    </Style> 
</Page.Resources> 





Regards, 
Mohanram A. 



SI Simon December 23, 2020 01:10 PM UTC

Hi Mohanram, thanks for your reply.

Thanks for the link for the third query-this worked well.
Based on your answer to the second last query, I've worked around the last two queries by creating new columns to act as header rows and turning off the 'normal' row header.

For the first two queries, I'm not trying to change the filter and sort icon style, but where and how the icons appear.
I've modified the column header data template to have other information, however the filter icon appears on top of this. This isn't a problem when the column is wide:

But when the column is narrow the other content in the header is covered up:


I'm looking to be able to place the filter and sort buttons where I want them in the header template (or in another header row beneath).

Kind regards,
Simon


MA Mohanram Anbukkarasu Syncfusion Team December 24, 2020 02:31 PM UTC

Hi Simon,  

Thanks for the update.   

We are currently validating this. We will check and update with further details on December 29,  2020. We appreciate your patience until then.   

Regards,  
Mohanram A. 



SI Simon December 29, 2020 04:06 PM UTC

Thanks Mohanram.
I'm also finding I can't left click anything in the header without triggering the column to sort-but perhaps the solution to the other issue will fix that too.


DM Dhanasekar Mohanraj Syncfusion Team December 30, 2020 01:15 PM UTC

Hi Simons, 

Sorry for the inconvenience caused. 

We are still working on this we will check and update with further details on January 04, 2021. 

We appreciate your patience until then.  

Regards,
Dhanasekar Mohanraj. 



SI Simon January 9, 2021 07:10 PM UTC

Hi Dhanasekar,

any update on this please?

Thanks,
Simon


MA Mohanram Anbukkarasu Syncfusion Team January 11, 2021 11:52 AM UTC

Hi Simon, 

Sorry for the inconvenience caused.  

From the provided details and screenshots, we suspect that you have used header template to add addition information to the header. If your requirement is to have additional information on the header cell of the columns, you can achieve this without using header template by directly using GridColumn.HeaderText property as shown in the following code example.  

Code example :  

// By using mapping name of the column. 
this.dataGrid.Columns["DepthNumeric"].HeaderText = "DataSet1 Depth Numeric"; 
 
//OR 
 
// By using index of the column. 
this.dataGrid.Columns[1].HeaderText = "DataSet1 Depth Numeric"; 

Please revert to us with details, if this doesn'r resolve the reported problem. 

Regards, 
Mohanram A. 



SI Simon January 11, 2021 06:45 PM UTC

Hi Mohanram,

You're correct that I've modified the header template. However the other items I've added are comboboxes (but without borders), so unfortunately I cannot just add to the header text. This would also not prevent the sort and filter buttons from overlapping them.

Is it possible to trigger the sorting and filter dialogues from custom buttons that I can add to my template? I could then just switch the built in ones off with a style setter.

Kind regards,
Simon


MA Mohanram Anbukkarasu Syncfusion Team January 12, 2021 11:49 AM UTC

Hi Simon, 

Thanks for the update.  

You can resolve this problem by setting ColumnSizer as GridLengthUnitType.SizeToHeader and adjusting the header padding to avoid overlapping of the filter and sort icons with the text by creating custom GridColumnSizer as shown in the following code example.  

Code example :  

public class GridColumnSizerExt : GridColumnSizer 
 { 
     public GridColumnSizerExt(SfDataGrid dataGrid) : base(dataGrid) 
     { 
 
     } 
 
     //Calculate Width for the column when ColumnSizer is SizeToHeader 
     protected override double CalculateHeaderWidth(GridColumn column, bool setWidth = true) 
     { 
         var padding = 30; 
         return base.CalculateHeaderWidth(column, setWidth) + padding; 
     } 
 } 

We have prepared a simple sample with header template and it is available in the following link for your reference.  


Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Marked as answer

SI Simon January 19, 2021 06:07 PM UTC

Hi Mohanram,

Unfortunately editing the padding/margins used by the column or header template just moves things sideways or makes the columns wider.

I have achieved something what I'm after by adding the comboboxes to an unbound row beneath the header, allowing me to use the full widths of the cells in this row.

Kind regards,
Simon


MA Mohanram Anbukkarasu Syncfusion Team January 20, 2021 11:25 AM UTC

Hi Simon, 

Thanks for the update. 

We are glad to know that you have resolved the problem in your end. Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 



Loader.
Up arrow icon