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

RadDataGrid with specific Columns, Aggregation and Grouping in C#

8 Answers 160 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 13 Feb 2018, 12:41 AM

Hi, 

I am having an issue with a custom defined datagrid with specific columns, aggregation and grouping and it does not work...well, not in C#.

The grouping works 100% if defined in XAML, but its hit and miss for c#, mostly miss.

Aggregation has never worked.

I am basically generating PivotItems... which works, and then I am populating each pivot with a datagrid with the specific columns defined, as well as Grouping and Aggregation rules.  The population of the PivotItems, DataGrids and the Data all work perfectly except the Aggregation and Grouping.

I have even tried using a XAML template... also doesn't work, so I am at a loss.

Could someone please provide some tips as to what I am doing wrong.  Any help or suggestions would be greatly appreciated.

Thanks

My Code is below:

01.private void BuildPivots()
02.{
03.    if (App.Categories != null)
04.    {
05.        foreach (Categories Category in App.Categories)
06.        {
07.            Home_PivotShell.Items.Add(new PivotItem
08.            {
09.                Header = Category.Name,
10.                Name = Category.Id,
11.                Content = new RadDataGrid
12.                {
13.                    AutoGenerateColumns = false,
14.                    UserEditMode = DataGridUserEditMode.External,
15.                    ItemsSource = App.DataSet.Where(x => x.CategoryId == Category.Id),
16.                    GroupDescriptors =
17.                    {
18.                        new PropertyGroupDescriptor() { PropertyName = "Name", DisplayContent = "Description"}
19.                    },
20.                    AggregateDescriptors =
21.                    {
22.                        new PropertyAggregateDescriptor() { PropertyName = "Column1", Function = KnownFunction.Count}
23.                    },
24.                    Columns =
25.                    {
26.                        new DataGridTextColumn() { PropertyName = "Name", Header = "Description" },
27.                        new DataGridTextColumn() { PropertyName = "Column1" },
28.                        new DataGridTextColumn() { PropertyName = "Column2" },
29.                        new DataGridTextColumn() { PropertyName = "Column3" },
30.                        new DataGridTextColumn() { PropertyName = "Column4" },
31.                        new DataGridTextColumn() { PropertyName = "Column5" },
32.                        new DataGridTextColumn() { PropertyName = "Column6" },
33.                        new DataGridTextColumn() { PropertyName = "Column7" },
34.                    }
35.                }
36.            });
37.        }
38.    }
39.}

8 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 15 Feb 2018, 10:59 AM
Hi, Pierre,

I have created a sample based on the information you have provided and I could not observe an issue with the grouping through the code-behind. Furthermore, note that the Aggregate functionality does not expose its own UI and is just an API. You can get the aggregate values as follows:

private void DataGrid_Loaded(object sender, RoutedEventArgs e)
       {
           this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
           {
               var dataView = (sender as RadDataGrid).GetDataView();
               var aggregateValues = dataView.GetAggregateValues("Column1", null);
               var aggregateValue = dataView.GetAggregateValue(0, null);
           });
       }
Eventually, you can feed the information to a control of your choice and show it in your UI.

I have attached a sample for your reference.

Regards,
Stefan Nenchev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Stefan Nenchev
Telerik team
answered on 15 Feb 2018, 11:00 AM
Hi, 

I forgot to attach the sample. Here it goes.

Regards,
Stefan Nenchev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pierre
Top achievements
Rank 1
answered on 15 Feb 2018, 12:17 PM

Hi Stefan,

Brilliant, thank you very much.

I have since fixed the grouping, although I do not quite know what I did to fix it, let alone break it in the first place... oh well. :)

So that is the piece of the aggregation puzzle I was missing... thank you very much... I will give it a go and post my results.

Thanks again

Pierre

0
Pierre
Top achievements
Rank 1
answered on 16 Feb 2018, 12:15 AM

Hi Stefan,

This is great, again thank you very much.

I have two other items, is there a way to have the Aggregate value appear in the Grouping line and how would I go about having multiple aggregated columns?

Regards

Pierre

0
Stefan Nenchev
Telerik team
answered on 19 Feb 2018, 01:29 PM
Hi, Pierre,

Regarding your first question on showing the aggregates in the group row - the functionality is not available out of the box but can be achieved by applying a custom content to the header row. I have added another project for your reference(it uses the XAML syntax for convenience but you can set it up programmatically as well). Please have a look at it. Note that I am basically coming up with the logic in the converter which is used so you can take a similar approach and expose whatever data you need.

As for the multiple aggregation, you can add different AggregateDescriptors to the collection of the RadDataGrid and eventually access them through the dataView.GetAggregateValues method which should return several values in case you have more than 1 function per property.

I hope the information will be useful.

Regards,
Stefan Nenchev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pierre
Top achievements
Rank 1
answered on 19 Feb 2018, 09:26 PM

Hi Stefan, 

That would be a great help, unfortunately it seems you have attached the previous example.

Thanks

Pierre

0
Accepted
Stefan Nenchev
Telerik team
answered on 20 Feb 2018, 08:42 AM
Hello, Pierre,

It seems that my percentage of correctly attached projects is quite low, need to work on it :). Sorry for that, here is the actual project.

Regards,
Stefan Nenchev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pierre
Top achievements
Rank 1
answered on 21 Feb 2018, 10:11 PM

Many thanks for your help Stefan :)

Worked beautifully.

I have moved to using a template for the creation of the Pivot and DataGrid within and using your examples has given the result I was looking for.

Thanks again.

Tags
DataGrid
Asked by
Pierre
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Pierre
Top achievements
Rank 1
Share this question
or