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

RadGrid Subtotal details table

3 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 26 Mar 2015, 10:51 PM
I am fairly new to telerik control and have an issue with radgrid.  I have a radgrid that has a master and a detail table.  If I try to use the "Aggregate" to sum the columns in the footer it give me the total for the complete data source for the details table.  I would like it to only display the total for the master table item is expanded.  I have attached an image that shows the current behavior.  Any help in getting me moving in the right direction would be great.  

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 31 Mar 2015, 11:48 AM
Hello Joseph,

By default, the aggregates should summarize only the detail records, exactly how you described. Can you please verify that you are not using DataBind() to bind the grid? Please note that performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding


Here is a live demonstration for declarative binding of a hierarchy:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/insert-update-delete-hierarchy/defaultcs.aspx
And also programmatic:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/programmatic-hierarchy/defaultcs.aspx


Looking forward to your reply.

Regards,
Eyup
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Joel Kraft
Top achievements
Rank 2
answered on 31 May 2018, 07:48 PM

Hello,

I am seeing this issue in R2 2018. I have a RadGrid with a master-detail relationship. The aggregates in the footer of the detail table is definitely including more than that particular instance of the detail.

This is the basic definition of the grid, with extra columns removed:

<TELERIK:RadGrid runat="server" ID="grdInvoices" AutoGenerateColumns="false" ShowFooter="true"
    OnNeedDataSource="grdInvoices_NeedDataSource" OnItemDataBound="grdInvoices_ItemDataBound" OnItemCommand="grdInvoices_ItemCommand">
    <MasterTableView CommandItemDisplay="Top" Name="Invoices" HierarchyLoadMode="Client" DataMember="Invoices" DataKeyNames="invoiceid" EditMode="EditForms">
        <Columns>
            <TELERIK:GridHyperLinkColumn DataNavigateUrlFields="invoiceid" DataNavigateUrlFormatString="InvoiceDisplay.aspx?gi={0}" Target="_blank" DataTextField="invoiceid" DataTextFormatString="GI{0}" HeaderText="ID" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" />
            <TELERIK:GridBoundColumn DataField="totalcharges" DataFormatString="{0:C}" HeaderText="Charges" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right" Aggregate="Sum" />
        </Columns>
        <DetailTables>
            <TELERIK:GridTableView DataMember="Lines" Caption="Items" NoDetailRecordsText="This invoice has no lines.">
                <Columns>
                    <TELERIK:GridBoundColumn DataField="linenumber" HeaderText="#" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                    <TELERIK:GridBoundColumn DataField="totallineamount" DataFormatString="{0:C}" HeaderText="Total" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right" Aggregate="Sum" />
                </Columns>
                <ParentTableRelation>
                    <TELERIK:GridRelationFields MasterKeyField="invoiceid" DetailKeyField="invoiceid" />
                </ParentTableRelation>
            </TELERIK:GridTableView>
            <TELERIK:GridTableView DataMember="Payments" Caption="Payments" NoDetailRecordsText="This invoice has no payments posted.">
                <Columns>
                    <TELERIK:GridBoundColumn DataField="paymentnumber" HeaderText="#" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
                    <TELERIK:GridBoundColumn DataField="paymentamount" DataFormatString="{0:C}" HeaderText="Payment" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right" Aggregate="Sum" />
                    <TELERIK:GridBoundColumn DataField="feeamount" DataFormatString="{0:C}" HeaderText="Fees" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" FooterStyle-HorizontalAlign="Right" Aggregate="Sum" />
                </Columns>
                <ParentTableRelation>
                    <TELERIK:GridRelationFields MasterKeyField="invoiceid" DetailKeyField="invoiceid" />
                </ParentTableRelation>
            </TELERIK:GridTableView>
        </DetailTables>
    </MasterTableView>
</TELERIK:RadGrid>

 

I'm attaching a partial screenshot of what the aggregates actually look like. The first total is displaying as $805, when there is only one line for $120. The others show too high a value, as well.

0
Eyup
Telerik team
answered on 05 Jun 2018, 02:10 PM
Hello Joel,

When using programmatic binding to implement an hierarchical structure, please use DetailTableDataBind event handler to bind the inner tables and remove the ParentTableRelation section:
https://www.telerik.com/support/kb/aspnet-ajax/grid/details/how-to-bind-radgrid-properly-on-server-side

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Joseph
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Joel Kraft
Top achievements
Rank 2
Share this question
or