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

[Solved] Aggregate question

1 Answer 156 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kumar
Top achievements
Rank 1
Kumar asked on 04 Mar 2009, 10:55 PM
I have an XML file like the following
<xml>
   <Department>
         <Description>Department1</Description>
         <SubDepartment>
               <Description>SubGroup1</Description>
               <Personal>
                     <Description>name1</Description>
                     <Salary>10000</Salary>
               </Persona>
               ... More personal
         </SubDepartment>
         .... more subdepartment
    </Department>
    .... more Department
</xml>

I would like to create a hierarchical datagrid with the information provided above. I would like to have the grid something like the following

Description       Salary

1. When All fields collapsed, I want the row to have department description and total salary of all the personal in all sub department in department.
2. When Department expanded, it should show all subdeaprtment description and its associated total and total will go away from department.
3. When personal expanded only personal will show description and salary.

is it possible in the DataGrid you have provided.

1 Answer, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 07 Mar 2009, 02:47 PM
Hello Kumar,

In my opinion the best way to show your data is to make it flat and use groups and aggregates of RadGridView. Attached is a sample project.

You can use hierarchy too. But that looks a little odd.

public partial class Page : UserControl 
    public Page() 
    { 
        InitializeComponent(); 
        gridView.ItemsSource = new[] 
                                   { 
                                       new Personal { Department = "Department 1", SubDepartment = "Sub 1", Name = "John", Salary = 33000.0 }, 
                                       new Personal { Department = "Department 1", SubDepartment = "Sub 1", Name = "Peter", Salary = 32000.0 }, 
                                       new Personal { Department = "Department 2", SubDepartment = "Sub 2", Name = "Bathman", Salary = 11000.0 }, 
                                       new Personal { Department = "Department 2", SubDepartment = "Sub 3", Name = "Robin", Salary = 44000.0 } 
                                   }; 
    } 
 
public class Personal 
    public string Department { getset; } 
    public string SubDepartment { getset; } 
    public string Name { getset; } 
    public double Salary { getset; } 

<UserControl x:Class="SilverlightApplication7.Page" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"  
    xmlns:data="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data"  
    xmlns:GridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"  
    Width="800" Height="600"
    <Grid x:Name="LayoutRoot" Background="White"
        <Controls:RadGridView x:Name="gridView" Grid.Row="1" AutoGenerateColumns="False" ShowGroupPanel="False"
            <Controls:RadGridView.Columns> 
                <GridView:GridViewDataColumn HeaderText="Name" UniqueName="Name" /> 
                <GridView:GridViewDataColumn HeaderText="Salary" UniqueName="Salary" /> 
            </Controls:RadGridView.Columns> 
            <Controls:RadGridView.GroupDescriptions> 
                <data:RadGroupDescription PropertyName="Department" SortDirection="Ascending"
                    <data:RadGroupDescription.AggregateFunctions> 
                        <data:SumFunction FunctionName="TotalSalaries" SourceField="Salary" Caption="Total salaries:" /> 
                    </data:RadGroupDescription.AggregateFunctions> 
                </data:RadGroupDescription> 
                <data:RadGroupDescription PropertyName="SubDepartment" SortDirection="Ascending"
                </data:RadGroupDescription> 
            </Controls:RadGridView.GroupDescriptions> 
        </Controls:RadGridView> 
    </Grid> 
</UserControl> 


Kind regards,
Jordan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Kumar
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Share this question
or