Aggregates extension method produces exception

4 posts, 0 answers
  1. Mikhail
    Mikhail avatar
    5 posts
    Member since:
    May 2014

    Posted 23 Sep Link to this post

    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?

  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 27 Sep Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Mikhail
    Mikhail avatar
    5 posts
    Member since:
    May 2014

    Posted 27 Sep in reply to Angel Petrov Link to this post

    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.

  5. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 29 Sep Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready