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

SfDataGrid: how to bind the header of a column to a ViewModel?

Is there any way to bind the header of a column to a property of the ViewModel?

I tried 
<syncfusion:GridTextColumn MappingName="ColumnName"
                                               HeaderText="{Binding ColumnNameLabel}" />

but that fails.

Is there a way to do that?



4 Replies

JG Jai Ganesh S Syncfusion Team July 9, 2013 07:25 AM UTC

Hi Andreas,

Thanks for contacting syncfusion support.

 

We have analyzed your query.You can achieve the requirement by setting ViewModel as source value for the binding. We have created a simple sample to achieve this requirement and please check the sample under the following location,

 

Sample: http://www.syncfusion.com/downloads/Support/DirectTrac/110157/Headerbinding-1493656320.zip

 

Please let us know if you need further assistance.

 

Thank you,

Jai Ganesh S



AM Andreas Myka July 9, 2013 08:24 AM UTC

Works great. Thanks for the fast and helpful reply!

Best,
Andreas


JA Jason March 17, 2014 08:02 PM UTC

Can you please provide an example of binding the header text without using a static resource?

In my situation I need to bind the heading text to a property on the data templates data context, the view model cannot be instantiated within XAML and the heading text value needs to change as the view model property is updated.
 
I have tried using various binding paths including element name etc but I can't seem to get it going. Any help would be appreciated.


AN Ashok N Syncfusion Team March 19, 2014 10:43 AM UTC

Hi Jason,

You can achieve your requirement by using ElementName Binding as shown in the following code snippet.

<syncfusion:SfDataGrid.Columns>

                <syncfusion:GridTextColumn MappingName="EmployeeId" HeaderText="{Binding ElementName=datagrid, Path=DataContext.CustomHeaderText, Mode=TwoWay}"/>

</syncfusion:SfDataGrid.Columns>

We have created a sample to achieve this requirement and please check the following sample link. 

 http://www.syncfusion.com/uploads/user/directTrac/120528/Headerbinding-1069340575.zip

 

Please let us know if you require further assistance 

Thanks,

Ashok


Loader.
Live Chat Icon For mobile
Up arrow icon