This is a migrated thread and some comments may be shown as answers.

Expression column in child table

2 Answers 54 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 18 Mar 2014, 07:52 PM
I have the following data structure in my view model:

ViewModel{
    List of ClientInfos
}

ClientInfos{
    double HourlyRate
    List of ProjectInfos
}

ProjectInfos{
    TimeSpan TimeSpent
    List of WorkItems
}

After much playing around, I have managed to reflect this structure in the UI using a GridView, two child table relations alongside HierachicalChildTemplates as detailed below:

<telerik:RadGridView x:Name="gridView" AutoGenerateColumns="False" IsReadOnly="True" ItemsSource="{Binding ClientInfos}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Client" />
            </telerik:RadGridView.Columns>            
            <telerik:RadGridView.ChildTableDefinitions>
                <telerik:GridViewTableDefinition  />
            </telerik:RadGridView.ChildTableDefinitions>
            
            <telerik:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <telerik:RadGridView x:Name="ProjectList" ShowGroupPanel="False" IsFilteringAllowed="False" CanUserSortColumns="False" CanUserFreezeColumns="False" AutoGenerateColumns="False" ItemsSource="{Binding Projects}">
                        <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Project" />
                        <telerik:GridViewDataColumn DataMemberBinding="{Binding WorkingHours}" Header="Day length (hr)" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding DailyRate}" Header="Day Rate" DataFormatString="{}{0:F}" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding HourlyRate}" Header="Hourly Rate" DataFormatString="{}{0:F}" />
                        </telerik:RadGridView.Columns>

                        <telerik:RadGridView.ChildTableDefinitions>
                            <telerik:GridViewTableDefinition  />
                        </telerik:RadGridView.ChildTableDefinitions>

                        <telerik:RadGridView.HierarchyChildTemplate>
                            <DataTemplate>
                                <telerik:RadGridView x:Name="WorkItemList" ShowGroupPanel="False" IsFilteringAllowed="False" CanUserSortColumns="False" CanUserFreezeColumns="False" AutoGenerateColumns="False" ItemsSource="{Binding WorkItems}">
                                    <telerik:RadGridView.Columns>
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}" Header="Work Item" />
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding DateLogged}" Header="Logged" DataFormatString="{}{0:dd/MM/yyyy}" />
                                        <telerik:GridViewDataColumn DataMemberBinding="{Binding TimeSpent}" Header="Time Spent" />
                                        <telerik:GridViewExpressionColumn Header="Total value in stock" UniqueName="TotalValue" Expression="???" />
                                    </telerik:RadGridView.Columns>
                                </telerik:RadGridView>
                            </DataTemplate>
                        </telerik:RadGridView.HierarchyChildTemplate>

                    </telerik:RadGridView>
                </DataTemplate>
            </telerik:RadGridView.HierarchyChildTemplate>
        </telerik:RadGridView>


The issue I am querying here is associated with the second child table responsible for listing the "WorkItems" within the rows "Projects" collection.   I desire a column in the work items child table which lists the financial value of that work item.  This is calculated by taking the "HourlyRate" property which is stored in the associated item for the WorkItem entity and multiplying that by the TimeSpent property value on the WorkItem entity.

My question is what is the syntax I must use in the Expression property of this expression column?  I am using an MVVM architecture so a pure-xaml solution is preferable.  I am not invested in the idea of using the child relation table setup so if anyone has any better ideas on how to represent this hierarchical data on the UI, im all ears.

Thank you for your time and effort.


2 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 18 Mar 2014, 07:56 PM
I do apologise, I incorrectly laid out my view model structure.  Here is the correct data structure:

ViewModel{
    List of ClientInfos
}

ClientInfos{
   List of ProjectInfos
}

ProjectInfos{
    double HourlyRate
    List of WorkItems
}

WorkItem{
    TimeSpan TimeSpent
}
0
Nick
Telerik team
answered on 21 Mar 2014, 11:56 AM
Hi David,

The easiest way to achieve this is to introduce a direct property in the WorkItem class that will give you the value and bind to it directly. The other is to use a reference to the parent project and use an expression to get the value. 

I am attaching a sample with both approaches. 

Hope this helps. 


Regards,
Nik
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Nick
Telerik team
Share this question
or