Aggregating a Template Column

10 posts, 0 answers
  1. Mark H
    Mark H avatar
    38 posts
    Member since:
    Aug 2008

    Posted 06 Jul 2009 Link to this post

    I have followed the info in http://www.telerik.com/community/forums/aspnet-ajax/grid/custom-aggregate-on-a-templated-column-with-grouping.aspx

    it helps but doesn't get me quite where I need to be. I have a grid which I can declaratively group by at a couple of levels - bascially order lines within order reference within period. I have one column which is the currency equivalent for each line and this value is calculated in the ItemdataBound event.

    I want either the Group Header or the Group Footer to show me the sum of this column and for the interim sums to also be shown - eg total value of each order reference at the innermost level and also total value of all orders in the period in the main group. Ideally if the user elects to drah and drop other groupings I would want the totals to be rolled up accordingly.

    The sample code in teh forum msg above has two probs - one it seems to only work at the innermost level ie the outermost group header doesn't recursively sum everything below it. And two it seems to overwrite the group header text so any other useful text is lost to the label that is created in the code.

    Is there any way to declaratively specify an aggregate on the template column?

    T
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 09 Jul 2009 Link to this post

    Hello Mark H,

    Specifying declarative aggregates for RadGrid template columns is not supported by our web grid. You may consider the programmatic approach from the forum thread you pointed or use built-in GridCalculatedColumn (if appropriate) to calculate the currency equivalent and group by its values in a declarative manner.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Mark H
    Mark H avatar
    38 posts
    Member since:
    Aug 2008

    Posted 09 Jul 2009 Link to this post

    Thanks Sebastian,

    I'm currently using the code route - however I need a clue how to make this work for parent group headers - ie the supplied example I referenced works fine for a group header with data rows as children but I need to make sure that if I have multiple group levels that the aggregation works all the way up the chain - how do I do this?

    Mark
  4. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 09 Jul 2009 Link to this post

    Hello Mark H,

    If you stick to the programmatic approach, you will need to implement your custom complex logic which to propagate the calculated aggregates when having several nested levels of grouping. This is not necessary if you consider using built-in GridCalculatedColumn since the aggregated values for that column will be re-calculated automatically.

    Best regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Mark H
    Mark H avatar
    38 posts
    Member since:
    Aug 2008

    Posted 11 Jul 2009 Link to this post

    OK I'm trying that but I'm seeing some odd behaviour.

    I'm hooking ItemDataBound and when I just have GridBoundColumns and GridTemplateColumns in my collection I find that e.Item.DataItem can be cast and used as a DataRowView which is very handy. However as soon as I make one of the columns a GridCalculatedColumn my cast fails and the debugger tells me I'm getting a DynamicClass1 passed in teh DataItem member instead - is this correct and where can I find docs on it? It means I'm now potentially going to have to change all my code that was checking fields in the DataRowView :(

    Mark
  6. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 13 Jul 2009 Link to this post

    Hello Mark H,

    In case you use the .NET 3.5 build of Telerik.Web.UI.dll, can you please check whether the same behavior happens when you set the EnableLinqExpressions property of the grid to false? With this build by default LINQ queries will be used to generate the expression for the GridCalculatedColumn and in this way you will force it to apply the .NET 2.x syntax for them, thus keeping the DataItem of type DataRowView.

    Best regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Andriy Mudriy
    Andriy Mudriy avatar
    11 posts
    Member since:
    Dec 2009

    Posted 20 Dec 2011 Link to this post


    Could you please clarify us can we use aggregation for GridTemplateColumn in last Telerik version? Thanks.
  8. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 21 Dec 2011 Link to this post

    Hello Andriy,

    The concepts for supporting aggregates with templated and calculated grid columns explained in this forum thread are still applicable. Consider the solutions suggested below and choose the most appropriate one for your scenario.

    Best regards,
    Sebastian
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  9. J2K
    J2K avatar
    34 posts
    Member since:
    Sep 2005

    Posted 08 Oct 2015 in reply to Sebastian Link to this post

    Incredibly lame.  Another reason not use to Telerik controls. Thank you.
  10. Eyup
    Admin
    Eyup avatar
    3666 posts

    Posted 13 Oct 2015 Link to this post

    Hello,

    I am not sure exactly what you want to achieve, however, the following definition should work correctly with aggregates:
    <telerik:GridTemplateColumn DataField="Freight" DataType="System.Decimal"
        FilterControlAltText="Filter Freight column" HeaderText="Freight"
        SortExpression="Freight" UniqueName="Freight" Aggregate="Sum">
        <ItemTemplate>
            <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("Freight") %>'>
            </asp:LinkButton>
        </ItemTemplate>
    </telerik:GridTemplateColumn>

    Hope this helps.

    Regards,
    Eyup
    Telerik
    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