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

Aggregates extension method produces exception

3 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mikhail
Top achievements
Rank 1
Mikhail asked on 23 Sep 2016, 12:47 PM

I am trying to create extension method for GridBoundColumnBuilder for setting aggregate cell for column and format it. The attempt is in following style (grid_ext_1.png).

My intent is to set dataSource.Aggregates for column to count sum of all items, and ClientFooterTemplate to perform formatting of aggregate cell.

Another intent is to reduce the whole code -  as I have already bound property of class to column (in the GridColumnFactory), I do not want to write another method for setting aggregate item (in the DataSourceAggregateDescriptorFactory). I have ~40 columns in one grid and it is really hurts to write method for every column 2 times.

In the case of the attached code I have an exception "Ambigous Match Found". Due to head of stack trace:

   in System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
   in System.Type.GetProperty(String name)
   in Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.<>c__DisplayClassc.<CreateProjectionMemberBindings>b__b(AggregateFunction f, Expression e)
   in Kendo.Mvc.Extensions.EnumerableExtensions.<ZipIterator>d__7`3.MoveNext()
   in System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   in System.Dynamic.Utils.CollectionExtensions.ToReadOnly[T](IEnumerable`1 enumerable)
   in System.Linq.Expressions.Expression.MemberInit(NewExpression newExpression, IEnumerable`1 bindings)
   in Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateProjectionInitExpression()
   in Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateAggregateFunctionsProjectionMemberBinding()
   in Kendo.Mvc.Infrastructure.Implementation.Expressions.QueryableAggregatesExpressionBuilder.<CreateMemberBindings>d__0.MoveNext()
   in System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   in System.Dynamic.Utils.CollectionExtensions.ToReadOnly[T](IEnumerable`1 enumerable)
   in System.Linq.Expressions.Expression.MemberInit(NewExpression newExpression, IEnumerable`1 bindings)
   in Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateSelectBodyExpression()
   in Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilder.CreateSelectExpression()
   in Kendo.Mvc.Infrastructure.Implementation.Expressions.GroupDescriptorExpressionBuilderBase.CreateQuery()
   in Kendo.Mvc.Extensions.QueryableExtensions.Aggregate(IQueryable source, IEnumerable`1 aggregateFunctions)
   in Kendo.Mvc.Extensions.QueryableExtensions.CreateDataSourceResult[TModel,TResult](IQueryable queryable, DataSourceRequest request, ModelStateDictionary modelState, Func`2 selector)
   in Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable queryable, DataSourceRequest request, ModelStateDictionary modelState)
   in Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable enumerable, DataSourceRequest request)
   in Kendo.Mvc.UI.DataSource.Process(DataSourceRequest request, Boolean processData)
   in Kendo.Mvc.UI.Grid`1.ProcessDataSource()

it seems that aggregates builder fails to get a property of class. But if I had an duplicate property name - I would find it at compilation time.

So, I have no idea what Kendo finds ambiguous.

Can you point out what I'm doing wrong? How to write an extension method which will satisfy my objectives correctly?

3 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 27 Sep 2016, 10:36 AM
Hello,

Could you please elaborate on why exactly do you want to create the extension method as I am experiencing difficulties understanding the scenario. Generally you should be able to set aggregates for the data source and format the result using a footer template.

Regards,
Angel Petrov
Telerik by Progress
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
Mikhail
Top achievements
Rank 1
answered on 27 Sep 2016, 10:53 AM

Hello, Angel, thank you for response.

I am doing the following to set aggregates:

@(Html.Kendo().Grid(Model).Name("reportGrid")
    .Columns(columns =>
    {
        columns.Bound(c => c.Payment).ClientFooterTemplate("#= kendo.toString(sum, 'n2')#");
        //another columns with footer data (40+)
    })
    .Resizable(resizable => resizable.Columns(true))
    .Reorderable(reorderable => reorderable.Columns(true))
    .Sortable(sortable => sortable.AllowUnsort(true).SortMode(GridSortMode.MultipleColumn))
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false)
        .Aggregates(aggregates =>
            {
                aggregates.Add(p => p.Payment).Sum();
                //another footer aggregates (40+)
            }))
)
And I am trying to create an extension method for reaching the following syntax:

@(Html.Kendo().Grid(Model).Name("reportGrid")
    .Columns(columns =>
    {
        columns.DecimalBoundWithSum(c => c.Payment);
        //another columns with footer data (40+)
    })
    .Resizable(resizable => resizable.Columns(true))
    .Reorderable(reorderable => reorderable.Columns(true))
    .Sortable(sortable => sortable.AllowUnsort(true).SortMode(GridSortMode.MultipleColumn))
    .DataSource(dataSource => dataSource
        .Ajax()
        .ServerOperation(false))
)

As you can see, it looks more prettier than the initial method. Also, as I written, it really hurts to set footer data for column in the two places.

You are right, I am able to set aggregates for the data source and format the result. This whole work is directed for reducing code size and number of repeating, in this case, column names.

0
Angel Petrov
Telerik team
answered on 29 Sep 2016, 10:43 AM
Hello Mikhail,

Implementing such method may require extending our helpers which is generally not supported. However I understand your concerns and suggest you to open a formal support ticket and attach a sample that illustrates the issue. That way we can examine and debug it carefully and if possible provide a straight to the point solution.

Regards,
Angel Petrov
Telerik by Progress
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
Tags
Grid
Asked by
Mikhail
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Mikhail
Top achievements
Rank 1
Share this question
or