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

Aggregate Function on Dynamically Created Columns

6 Answers 145 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Siddhant
Top achievements
Rank 1
Siddhant asked on 10 Jan 2013, 10:36 AM
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;
        }
    }

6 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 10 Jan 2013, 11:47 AM
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.

0
Siddhant
Top achievements
Rank 1
answered on 10 Jan 2013, 01:06 PM
How do i convert the entity so that it take only the  numeric property from it ?

0
Accepted
Dimitrina
Telerik team
answered on 10 Jan 2013, 01:17 PM
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.

0
Siddhant
Top achievements
Rank 1
answered on 10 Jan 2013, 01:33 PM
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
0
Siddhant
Top achievements
Rank 1
answered on 10 Jan 2013, 02:37 PM
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
0
Siddhant
Top achievements
Rank 1
answered on 11 Jan 2013, 07:18 PM
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
Tags
GridView
Asked by
Siddhant
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Siddhant
Top achievements
Rank 1
Share this question
or