GridViewExpressionColumn and Aggregating

4 posts, 0 answers
  1. Matthew
    Matthew avatar
    6 posts
    Member since:
    Aug 2013

    Posted 05 Sep Link to this post

    Hi,

    How can I add a sumfunction to a GridViewExpression column?
    for a GridViewDataColumn I simply add:

    <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction />
    </telerik:GridViewDataColumn.AggregateFunctions>

    and it works 100%, but when I do it for the same for GridViewExpressionColumn:

    <telerik:GridViewExpressionColumn.AggregateFunctions>
                <telerik:SumFunction />
     </telerik:GridViewExpressionColumn.AggregateFunctions>

    I get an error "No Generic method 'Sum' on type 'System.linq.Enumerable' is compatible with the supplied type arguments".
    The data in GridViewDataColumns is of Type Decimal, do i need to set the type of the expression column? if so, how?

    thanks.

    regards,
    Matthew

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 06 Sep Link to this post

    Hello Matthew,

    I'm afraid you cannot explicitly set a data type for a GridViewExpressionColumn, but you could define a generic AggregateFunction as documented in this article. I'm attaching a sample project to better demonstrate how you can implement this.

    Please give this a try and let me know if such an approach would work for you.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Matthew
    Matthew avatar
    6 posts
    Member since:
    Aug 2013

    Posted 06 Sep in reply to Dilyan Traykov Link to this post

    Hello Dilyan,

    Thanks. Your solution works for me, but please help me understand:
    If you have numeric values in the GridViewExpressionColumn, why does the standard sumfunction not work?

    Thanks.

    regards,
    Matthew

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 07 Sep Link to this post

    Hello Matthew,

    The reason the standard sum function does not work when using the GridViewExpressionColumn is that the function is not passed the calculated numeric values, but rather the whole bound objects as that is simply the way this type of column works.

    Thus, it cannot operate correctly without an explicit AggregationExpression being provided, which is the case of the custom sum function from the project in my previous reply.

    I hope that this clarifies things for you.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top