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

How to show total of a grid column in grid footer?..

7 Answers 743 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 25 Oct 2010, 01:37 PM
hey everyone,

I am using a radgrid where user inserts Order.Order are temporarily stored in radgrid using data table as data source.I want to show a total of all the values inside Amount column in the grid footer.How to achieve this?...

Thanks
Amit

7 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 25 Oct 2010, 02:37 PM
Hi Amit,

Please go through the online resources below and let me know if they are useful for you.
http://www.telerik.com/help/aspnet-ajax/grdtotalsingridfooters.html
http://demos.telerik.com/aspnet-ajax/grid/examples/groupby/groupfooter/defaultcs.aspx

Sincerely yours,
Pavlina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Amit
Top achievements
Rank 1
answered on 26 Oct 2010, 08:23 AM
Hey Pavlina,

Actually i wanted to know about the case where data table is used as radgrid's data source and there are no columns predefined in the radgrid.What to do with that?...

Thanks
Amit
0
Pavlina
Telerik team
answered on 26 Oct 2010, 12:18 PM
Hi Amit,

Please refer to the forum thread below which elaborates on how to set the aggregate property for the AutoGeneratedColumns:
http://www.telerik.com/community/forums/aspnet-ajax/grid/radgrid-footer-total-dynamically.aspx

Kind regards,
Pavlina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Amit
Top achievements
Rank 1
answered on 27 Oct 2010, 08:42 AM
Hi Pavlina,

I am not able to use any of the examples and demos,because they're all using predefined columns inside the grid,which is not my case.I have binded my grid to an empty datatable (which has just columns name defined within) as datasource.And i am using RadGrid to insert records which are inserted to datatable an simultaneously shown in the grid,which is when i want one of my column to show total of all column items in grid footer.My grid is--

<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
                        AllowSorting="True" GridLines="None" Skin="Hay" OnNeedDataSource="RadGrid1_NeedDataSource"
                        OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound"
                        PagerStyle-AlwaysVisible="true">
                        <MasterTableView>
                            <RowIndicatorColumn>
                                <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn>
                                <HeaderStyle Width="20px" />
                            </ExpandCollapseColumn>
                            <EditFormSettings EditFormType="Template">
                                <FormTemplate>
                                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                        <tr>
                                            <td colspan="2" style="font-size: medium">
                                                <b>Enter your Order Details here:</b>
                                                <br />
                                                <br />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <table border="0" cellpadding="0" cellspacing="0" width="100%" style="font-size: 12pt">
                                                    <tr>
                                                        <td>
                                                        </td>
                                                        <td>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 15%">
                                                            Product Name:
                                                        </td>
                                                        <td align="left" style="width: 85%">
                                                            <telerik:RadComboBox ID="RadComboBox1" runat="server" Skin="Hay" DataSourceID="SqlDataSource2"
                                                                MarkFirstMatch="true" AllowCustomText="true" DataValueField="Pid" DataTextField="ProductName"
                                                                EmptyMessage="Please select an Item" Height="150px" Width="145px">
                                                            </telerik:RadComboBox>
                                                            <asp:Button ID="btnCancel" runat="server" Style="float: right; margin-right: 10px;
                                                                color: black; font-weight: bold" Text="Cancel" />
                                                            <asp:Button ID="btnSave" Style="float: right; color: black; margin-right: 10px; font-weight: bold;"
                                                                Text="Save" runat="server" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 15%">
                                                            Rate:
                                                        </td>
                                                        <td align="left" style="width: 85%">
                                                            <asp:Label ID="lblRate" runat="server" />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 15%">
                                                            Qunatity:
                                                        </td>
                                                        <td align="left" style="width: 85%">
                                                            <telerik:RadNumericTextBox ID="txtQuantityE" runat="server" Skin="Hay" EmptyMessage="Enter Quantity"
                                                                SelectionOnFocus="CaretToEnd" ToolTip="Enter Quantity to place Order" Culture="English (United States)"
                                                                Height="14px" Width="141px" MaxValue="9999" MinValue="1">
                                                                <NumberFormat GroupSeparator="" DecimalDigits="0" AllowRounding="true" KeepNotRoundedValue="false" />
                                                                <ClientEvents OnKeyPress="KeyPress" />
                                                            </telerik:RadNumericTextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 15%">
                                                            Amount:
                                                        </td>
                                                        <td align="left" style="width: 85%">
                                                            <asp:Label ID="lblAmount" runat="server" />
                                                            <asp:HiddenField ID="Amount" runat="server" />
                                                            <br />
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="height: 4pt">
                                                        </td>
                                                        <td style="height: 4pt">
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </FormTemplate>
                            </EditFormSettings>
                            <HeaderStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Size="Medium"
                                Font-Strikeout="False" Font-Underline="False" Wrap="True" />
                        </MasterTableView>
                        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" EnableRowHoverStyle="true">
                        </ClientSettings>
                    </telerik:RadGrid>
and cs--
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
       {
           dtValues = new DataTable();
           dtValues.Columns.Add("ProductId");
           dtValues.Columns.Add("Items");
           dtValues.Columns.Add("Rate");
           dtValues.Columns.Add("Quantity");
           dtValues.Columns.Add("Amount");
           if (Session["Table"] != null)
           {
               dtValues = (DataTable)Session["Table"]; // retrieve DataTable from session
           }
           RadGrid1.DataSource = dtValues;
           Session["Table"] = dtValues; //store DataTable in session
       }
Can you help and suggest me with this....

Thanks
Amit
0
Princy
Top achievements
Rank 2
answered on 27 Oct 2010, 09:16 AM
Hello Amit,

I hope the following code will help you to achieve your requirement.

C#:
double total;
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            double fieldValue =Convert.ToDouble(dataItem["Amount"].Text);
            total += fieldValue; // find total value(of cell 'Amount')for each item
        }
        if (e.Item is GridFooterItem)
        {
            GridFooterItem footerItem = (GridFooterItem)e.Item;
            footerItem["Amount"].Text = total.ToString(); //insert result in the footer of corresponding column
        }
    }

Also refer the above mentioned documentation for more details on this.

Thanks,
Princy.
0
Chris Griffin
Top achievements
Rank 1
answered on 03 Nov 2010, 09:19 PM
The problem with this solution is that it is on the item databound function.  If you have paging enabled, then its only the total for the current page.
0
Pavlina
Telerik team
answered on 04 Nov 2010, 08:32 AM
Hello Chris,

Refer to the help article below for more information about how to displaying totals for all grid pages:
http://www.telerik.com/help/aspnet-ajax/grdtotalsingridfooters.html (Displaying totals for all grid pages
section)

Sincerely yours,
Pavlina
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Amit
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Amit
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Chris Griffin
Top achievements
Rank 1
Share this question
or