Aggregate Function on Dynamically Created Columns

7 posts, 1 answers
  1. Siddhant
    Siddhant avatar
    22 posts
    Member since:
    Jan 2013

    Posted 10 Jan 2013 Link to this post

    I have a grid whose coloumns are dynamically generated. I am trying to apply the sum aggregate function but its not working . could you please help with that. Also the columns use a converter.


    foreach (DayBE _dayBE in _days.OrderBy(x => x.date).ToList())
                {
                    string headerText = _dayBE.date.ToString("dd-MMM");
     
                    GridViewDataColumn gvdc = new GridViewDataColumn() { IsReadOnly=false, Header = headerText, DataMemberBinding = new Binding("period") { Converter = new GridFormatter(), ConverterParameter = new List<object>() { _dayBE.date } } };
                    //AggregateFunction sum = new MaxFunction();
                    //sum.Caption = "Total: ";
                    //gvdc.AggregateFunctions.Add(fn);
                    radGridView.Columns.Add(gvdc);
                }
     
     
     
     
    public class GridFormatter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                ObservableCollection<DayBE> weeks = value as ObservableCollection<DayBE>;
                var val = from w in weeks
                          where w.date.Equals((parameter as List<object>)[0])
                          select w.allocation;
                return val.FirstOrDefault();
            }
     
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                ObservableCollection<DayBE> _test1 = new ObservableCollection<DayBE>();
                DayBE _test = new DayBE();
                _test.date = System.Convert.ToDateTime((parameter as List<object>)[0].ToString());
                _test.allocation = System.Convert.ToDouble(value);
                _test1.Add(_test);
                return _test1;
            }
        }
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 10 Jan 2013 Link to this post

    Hello,

    You can check this help article for a reference. 

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Siddhant
    Siddhant avatar
    22 posts
    Member since:
    Jan 2013

    Posted 10 Jan 2013 Link to this post

    How do i convert the entity so that it take only the  numeric property from it ?

  4. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 10 Jan 2013 Link to this post

    Hi,

    In that case you could also use a Generic AggregateFunction to define some custom aggregate expressions.

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Siddhant
    Siddhant avatar
    22 posts
    Member since:
    Jan 2013

    Posted 10 Jan 2013 Link to this post

    ok so below is the code that i modified to create a aggregate expression , but  i m getting an error

    foreach (DayBE _dayBE in _days.OrderBy(x => x.date).ToList())
                {
                    string headerText = _dayBE.date.ToString("dd-MMM");
     
                    GridViewDataColumn gvdc = new GridViewDataColumn() { IsReadOnly = false, UniqueName = headerText,
     Header = headerText, DataMemberBinding = new Binding("period") { Converter = new GridFormatter(),
     ConverterParameter = new List<object>() { _dayBE.date } } };
     
                    var aggregate = new AggregateFunction<DayBE, double>
                    {
                        AggregationExpression = models =>  models.Sum(model => model.allocation),
                        Caption = "$US(mm)"
                    };
     
                    //SumFunction aggregate = new SumFunction();
                    gvdc.AggregateFunctions.Add(aggregate);
                    radGridView.Columns.Add(gvdc);
                }
     
    //The Entities are as follows
    public string associateID { get; set; }
    public string associateName { get; set; }
    public string projectID { get; set; }
    public string projectName { get; set; }
    public List<DayBE> period { get; set; }
     
    //The Second One is
    public DateTime date { get; set; }
    public double allocation { get; set; }
     
    //What I need is the sum of the allocation
  6. Siddhant
    Siddhant avatar
    22 posts
    Member since:
    Jan 2013

    Posted 10 Jan 2013 Link to this post

    OK the issue has been solved now the only thing that i want is that i want to display the same thing in the Footer instead of the header
    and should be scrollable according to the grid. The grid has 6 columns which are frozen
  7. Siddhant
    Siddhant avatar
    22 posts
    Member since:
    Jan 2013

    Posted 11 Jan 2013 Link to this post

    Ok so i have fixed the alignment by converting the footer into the header
    But now the problem is that the aggregate function is coming but the header say for example the name is name is missing.

    Could anyone tel me on how to get that
Back to Top