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-Column with Buttons

Hi,

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?

Regards
Harald

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:SfDataGrid.Columns>                
    <syncfusion:GridTextColumn MappingName="Name" /> 
    <syncfusion:GridTemplateColumn MappingName="City" syncfusion:FocusManagerHelper.WantsKeyInput="True"> 
        <syncfusion:GridTemplateColumn.CellTemplate> 
            <DataTemplate> 
                <Button  Content="Click" syncfusion:FocusManagerHelper.FocusedElement="True"   
Command="{Binding Path=DataContext.RowDataCommand,ElementName=sfGrid}" CommandParameter="{Binding}"/> 
            </DataTemplate> 
        </syncfusion:GridTemplateColumn.CellTemplate> 
    </syncfusion:GridTemplateColumn> 
 
</syncfusion:SfDataGrid.Columns> 
 
 
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. 
 
Regards, 
Muthukumar K 


Loader.
Up arrow icon