Access aggregate function results outside gridview?

4 posts, 1 answers
  1. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 12 Sep 2011 Link to this post

    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.

  2. Answer
    Vlad avatar
    11100 posts

    Posted 12 Sep 2011 Link to this post


     Indeed this is possible. Please check the code of the Button click in this demo

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Murray
    Murray avatar
    121 posts
    Member since:
    Aug 2010

    Posted 12 Sep 2011 Link to this post

    Thank you Vlad!
  5. Ruan
    Ruan avatar
    10 posts
    Member since:
    Nov 2010

    Posted 29 Sep 2011 Link to this post


    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";


     AggregateResult result = s.AggregateResults["Average"];
     if (result != null)
     MessageBox.Show("The smallest unit price is: " + result.FormattedValue.ToString());

     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);

     Grid.SetColumn(summaryView, _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.

Back to Top