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
close icon

SfDataGrid-Column with Buttons


I've a list of data items with two properties (ItemName (string) and ItemFlag (boolean)). I want to have a SfDataGrid with two columns. 

A text column displaying the ItemName and a button column displaying a button (bound to a viewmodel command) if ItemFlag=true or displaying nothing (or a disabled button) if ItemFlag=false.

I think I'll need a DataTemplateSelector but in my trials the overridden SelectTemplate method was never called.

Can you help me?


1 Reply

MK Muthukumar Kalyanasundaram Syncfusion Team July 21, 2017 03:47 AM UTC

Hi Harald, 
Thank you for contacting Syncfusion support. 
We have checked your query. You can pass the row information as a parameter to the command in ViewModel when clicking a button in TemplateColumn by passing the CommandParameter like the below code example,  
Code Snippet: 
    <syncfusion:GridTextColumn MappingName="Name" /> 
    <syncfusion:GridTemplateColumn MappingName="City" syncfusion:FocusManagerHelper.WantsKeyInput="True"> 
                <Button  Content="Click" syncfusion:FocusManagerHelper.FocusedElement="True"   
Command="{Binding Path=DataContext.RowDataCommand,ElementName=sfGrid}" CommandParameter="{Binding}"/> 
For your reference, we have attached sample and KB link. Could you please refer to it. 
Please let us know if you have any query. 
Muthukumar K 

Live Chat Icon For mobile
Up arrow icon