Clicking Button inside the DataGrid does nothing

1 Answer 94 Views
Buttons DataGrid
Boris
Top achievements
Rank 1
Boris asked on 16 Sep 2022, 05:12 PM | edited on 16 Sep 2022, 05:51 PM

When clicking button inside the DataGrid row the command doesn't get executed in the ViewModel.

Both Page and ViewModel are created by the DI container so I need to be able to pass the POCO object of the row where the button is clicked to the ViewModel.

 <telerikGrid:RadDataGrid DataContext="{x:Bind ViewModel}" ItemsSource="{x:Bind ViewModel.Source}" AutoGenerateColumns="False">
                            <telerikGrid:RadDataGrid.Columns>
                                <telerikGrid:DataGridTextColumn PropertyName="UserName" Header="User Name"/>
                                <telerikGrid:DataGridTextColumn PropertyName="UserEmail" Header="User Email"/>
                                <telerikGrid:DataGridBooleanColumn PropertyName="UserActiveIndicator" Header="User Status" />
                                <telerikGrid:DataGridDateColumn PropertyName="RecordCreated" Header="Date Created"/>
                                <telerikGrid:DataGridDateColumn PropertyName="RecordModified" Header="Date Modified"/>
                                <telerikGrid:DataGridTemplateColumn Header="Edit" Width="81">
                                    <telerikGrid:DataGridTemplateColumn.CellContentTemplate>
                                        <DataTemplate x:DataType="vm:SearchUserViewModel">
                                            <Button x:Name="editButton" Command="{x:Bind  EditUserCommand}" CommandParameter="{Binding }">
                                                <SymbolIcon Symbol="Edit"/>
                                            </Button>
                                        </DataTemplate>
                                    </telerikGrid:DataGridTemplateColumn.CellContentTemplate>
                                </telerikGrid:DataGridTemplateColumn>
                            </telerikGrid:RadDataGrid.Columns>
                        </telerikGrid:RadDataGrid>


1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 19 Sep 2022, 02:57 PM

Hello Boris,

I replied in the ticket that you have opened on the same topic, however I will post the reply here as well for visibility. 

"Note, that the DataContext for the elements inside the DataTemplate of the DataGridTemplateColumn will be the element from the ItemsSource of the RadDataGrid that represents that row. 

If the EditUserCommand is located in the ViewModel object, you will have to point the binding to it. A possible way for doing that is by setting its Source property. I am attaching a sample project demonstrating this approach for your reference."

Should you have any further questions, I would ask you to continue the discussion in the opened ticket in order to avoid duplicating replies. Thank you in advance for your understanding.

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Buttons DataGrid
Asked by
Boris
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or