This question is locked. New answers and comments are not allowed.
Is there a way to get aggregate results of named columns, but display them outside of the GridView or footer?
We want to have a custom display of aggregate results in an area to the side of the grid and have the results change depending in what filters are applied to the Grid.
Thanks
We want to have a custom display of aggregate results in an area to the side of the grid and have the results change depending in what filters are applied to the Grid.
Thanks
3 Answers, 1 is accepted
0
Accepted
Hello,
Vlad
the Telerik team
Indeed this is possible. Please check the code of the Button click in this demo.
Kind regards,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0

Murray
Top achievements
Rank 2
answered on 12 Sep 2011, 03:39 PM
Thank you Vlad!
0

Ruan
Top achievements
Rank 1
answered on 29 Sep 2011, 01:15 PM
Hi
I have a similar problem. I need to display the results of the aggregate functions, and have viewed the demo, that was pointed out.
This seems to work when I reproduced the code, but now I have the following problem:
We are using MVVM, the data of the grid is bound to an observable collection and the columns are auto-generated.
The functions are declared in the code-behind file of the grid, (not the best MVVM practice, I know, but it's the only way to get the columns), and the functions are added to the column successfully, but, the grid does not have any aggregate functions to calculate/ return results from.
Here is the code:
var s = (RadGridView)sender;
var headerStyle = (Style)Resources.Where(resource => (string)resource.Key == "GridViewHeaderCellStyle1").First().Value;
//The generated column.
var generatedColumn = (GridViewBoundColumnBase)e.Column;
e.Column.HeaderCellStyle = headerStyle;
var avg = new AverageFunction();
var mxf = new MaxFunction();
var mnf = new MinFunction();
var sf = new SumFunction();
avg.Caption = "Average";
generatedColumn.AggregateFunctions.Add(avg);
generatedColumn.AggregateFunctions.Add(mxf);
generatedColumn.AggregateFunctions.Add(mnf);
generatedColumn.AggregateFunctions.Add(sf);
s.CalculateAggregates();
AggregateResult result = s.AggregateResults["Average"];
if (result != null)
{
MessageBox.Show("The smallest unit price is: " + result.FormattedValue.ToString());
}
else
{
return;
}
var dataType = generatedColumn.DataType;
var summaryViewModel = new SummaryViewModel(0.00, 0.00,0.00,0);
var summaryView = new SummaryView();
ViewModelBinder.Bind(summaryViewModel, summaryView, null);
summaryViewModel.IsEnabled = true;
var cd = new ColumnDefinition{Width = new GridLength(generatedColumn.Width.DisplayValue, GridUnitType.Pixel)};
if (dataType == typeof(int) || dataType == typeof(double) || dataType == typeof(long))
{
summaryView.Width = 125.00;
cd.Width = new GridLength(summaryView.Width, GridUnitType.Pixel);
generatedColumn.Width = new GridViewLength(summaryView.Width + 8.00, GridViewLengthUnitType.Pixel);
SummaryGrid.ColumnDefinitions.Add(cd);
Grid.SetColumn(summaryView, _counter);
SummaryGrid.Children.Add(summaryView);
_summaryCollection.Add(summaryView);
}
else
SummaryGrid.ColumnDefinitions.Add(cd);
_counter++;
This code is executed on the generating columns event.
What I want to accomplish is to get the values/results of the aggregate functions to the "Summary" view.
The column has 4 aggregate functions (As I said this works successfully) but the grid does not generate any results.
Please tell me where I am doing something wrong.
Ruan
I have a similar problem. I need to display the results of the aggregate functions, and have viewed the demo, that was pointed out.
This seems to work when I reproduced the code, but now I have the following problem:
We are using MVVM, the data of the grid is bound to an observable collection and the columns are auto-generated.
The functions are declared in the code-behind file of the grid, (not the best MVVM practice, I know, but it's the only way to get the columns), and the functions are added to the column successfully, but, the grid does not have any aggregate functions to calculate/ return results from.
Here is the code:
var s = (RadGridView)sender;
var headerStyle = (Style)Resources.Where(resource => (string)resource.Key == "GridViewHeaderCellStyle1").First().Value;
//The generated column.
var generatedColumn = (GridViewBoundColumnBase)e.Column;
e.Column.HeaderCellStyle = headerStyle;
var avg = new AverageFunction();
var mxf = new MaxFunction();
var mnf = new MinFunction();
var sf = new SumFunction();
avg.Caption = "Average";
generatedColumn.AggregateFunctions.Add(avg);
generatedColumn.AggregateFunctions.Add(mxf);
generatedColumn.AggregateFunctions.Add(mnf);
generatedColumn.AggregateFunctions.Add(sf);
s.CalculateAggregates();
AggregateResult result = s.AggregateResults["Average"];
if (result != null)
{
MessageBox.Show("The smallest unit price is: " + result.FormattedValue.ToString());
}
else
{
return;
}
var dataType = generatedColumn.DataType;
var summaryViewModel = new SummaryViewModel(0.00, 0.00,0.00,0);
var summaryView = new SummaryView();
ViewModelBinder.Bind(summaryViewModel, summaryView, null);
summaryViewModel.IsEnabled = true;
var cd = new ColumnDefinition{Width = new GridLength(generatedColumn.Width.DisplayValue, GridUnitType.Pixel)};
if (dataType == typeof(int) || dataType == typeof(double) || dataType == typeof(long))
{
summaryView.Width = 125.00;
cd.Width = new GridLength(summaryView.Width, GridUnitType.Pixel);
generatedColumn.Width = new GridViewLength(summaryView.Width + 8.00, GridViewLengthUnitType.Pixel);
SummaryGrid.ColumnDefinitions.Add(cd);
Grid.SetColumn(summaryView, _counter);
SummaryGrid.Children.Add(summaryView);
_summaryCollection.Add(summaryView);
}
else
SummaryGrid.ColumnDefinitions.Add(cd);
_counter++;
This code is executed on the generating columns event.
What I want to accomplish is to get the values/results of the aggregate functions to the "Summary" view.
The column has 4 aggregate functions (As I said this works successfully) but the grid does not generate any results.
Please tell me where I am doing something wrong.
Ruan