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

Summed footer for custom grid template

3 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
WCRA Dev
Top achievements
Rank 1
WCRA Dev asked on 28 Jun 2010, 05:04 PM
I've created a custom grid template that displays 3 columns of data (see code below).  The data is then grouped by year.  How can I show a total for each of these three columns in the group footer?


                    <telerik:GridTemplateColumn HeaderStyle-Width="246" ItemStyle-Width="246"  
                        UniqueName="TemplateColumn2"
                        <HeaderTemplate> 
                            <table ID="Table1" border="0" cellpadding="0" cellspacing="0" width="246"
                                <tr> 
                                    <td align="center" colspan="3"
                                        Remaining Reserve<BR />Open MN Claims Only</td> 
                                </tr> 
                                <tr> 
                                    <td width="82px"
                                        <center> 
                                            Indemnity</center> 
                                    </td> 
                                    <td width="82px"
                                        <center> 
                                            Medical</center> 
                                    </td> 
                                    <td width="82px"
                                        <center> 
                                            Med Only</center> 
                                    </td> 
                                </tr> 
                            </table> 
                        </HeaderTemplate> 
                        <ItemTemplate> 
                            <table ID="Table2" border="0" cellpadding="0" cellspacing="0" width="246"
                                <tr> 
                                    <td align="right" width="82px"
                                        <%#DataBinder.Eval(Container.DataItem, "open_indemnity", "{0:c}")%> 
                                    </td> 
                                    <td align="right" width="82px"
                                        <%#DataBinder.Eval(Container.DataItem, "open_medical", "{0:c}")%> 
                                    </td> 
                                    <td align="right" width="82px"
                                        <%#DataBinder.Eval(Container.DataItem, "open_medonly", "{0:c}")%> 
                                    </td> 
                                </tr> 
                            </table> 
                        </ItemTemplate> 
                        <HeaderStyle Width="246px" /> 
                        <ItemStyle Width="78px" /> 
                    </telerik:GridTemplateColumn> 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jun 2010, 01:23 PM
Hello Christian,

I have tried following code for a similar scenaio in my application. I used custom code to calculate the sum and created table structure dynamically for aligning the footer text properly. Please modify the code according your need.

C#:
 
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        int length = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader).Length; 
        for (int i = 0; i < length; i++) 
        { 
            int result1 = 0; 
            int result2 = 0; 
            int result3 = 0; 
            GridGroupHeaderItem groupHeader = (GridGroupHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)[i]; 
            GridItem[] children = groupHeader.GetChildItems(); 
            foreach (GridDataItem child in children) 
            { 
                GridDataItem childItem = child as GridDataItem; 
                DataRowView DataRow = (DataRowView)child.DataItem; 
                result1 = Convert.ToInt32(DataRow["open_indemnity"].ToString()) + result1; 
                result2 = Convert.ToInt32(DataRow["open_medical"].ToString()) + result2; 
                result3 = Convert.ToInt32(DataRow["open_medonly"].ToString()) + result2; 
            } 
            GridGroupFooterItem groupFooter = (GridGroupFooterItem)RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter)[i]; 
        
            HtmlTable tbl = new HtmlTable(); 
            HtmlTableCell cell1 = new HtmlTableCell(); 
            HtmlTableRow row = new HtmlTableRow(); 
            row.Align = "right"
            cell1.Width = "100"
            cell1.BorderColor = "red"
            cell1.InnerText = result1.ToString(); 
            row.Cells.Add(cell1); 
            tbl.Rows.Add(row); 
            HtmlTableCell cell2 = new HtmlTableCell(); 
            cell2.InnerText = result2.ToString(); 
            cell2.Width = "100"
            row.Cells.Add(cell2); 
            tbl.Rows.Add(row); 
            HtmlTableCell cell3 = new HtmlTableCell(); 
            cell3.InnerText = result3.ToString(); 
            cell3.Width = "100"
            row.Cells.Add(cell3); 
            tbl.Rows.Add(row); 
            groupFooter["TemplateColumn2"].Controls.Clear(); 
            groupFooter["TemplateColumn2"].Controls.Add(tbl); 
        
        } 
    } 

I got border for the text displayed in GridGroupFooter and was able to resolve this by adding following css on page.

CSS:
 
 <style type="text/css"
        .RadGrid_Default .rgFooter td 
        { 
            border-bottom: none !important; 
            border-top: none !important; 
        } 
 </style> 

I hope this help you,
Princy.


0
WCRA Dev
Top achievements
Rank 1
answered on 29 Jun 2010, 03:42 PM
Thank you, this helps a lot.  The only issue now is that if the DataGrid is refreshed this error "Object reference not set to an instance of an object" happens on the line of code below:

result1 = Convert.ToDecimal(DataRow["open_indemnity"].ToString()) + result1; 

0
Mira
Telerik team
answered on 02 Jul 2010, 01:47 PM
Hello Christian,

I have followed your scenario and prepared a sample project for you demonstrating how the desired functionality can be achieved. You can find it attached to this message.

Please take a look at it and let me know whether it helps.

Best wishes,
Mira
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
WCRA Dev
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
WCRA Dev
Top achievements
Rank 1
Mira
Telerik team
Share this question
or