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

Footer not reloading after Expanding a column

2 Answers 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shane
Top achievements
Rank 1
Shane asked on 16 Aug 2010, 09:59 PM
Greetings,

I am populating my footer using the following ItemDataBound Event:

protected void rGridReporting_ItemDataBound(object sender, GridItemEventArgs e)
        {
            var subList = (List<VendorSubTotal>)Session["SubList"];

            if (!(e.Item is GridFooterItem) || subList.Count == 0) return;

            var footer = (GridFooterItem)e.Item;

            var t855 = subList.Sum(v => v.Total855);
            var t856 = subList.Sum(v => v.Total856);
            var t810 = subList.Sum(v => v.Total810);
            var p855 = t855 / subList.Count;
            var p856 = t856 / subList.Count;
            var p810 = t810 / subList.Count;

            footer["vName"].Controls.Add(new LiteralControl("<div style='color: Black; font-weight: bold;'>Report Grand Totals:</div> "));
            footer["t855"].Controls.Add(new LiteralControl("<div style='color: Black; font-weight: bold;'>" + t855 + "</div> "));
            footer["p855"].Controls.Add(new LiteralControl("<div style='color: Black; font-weight: bold;'>" + p855 + "</div> "));
            footer["t856"].Controls.Add(new LiteralControl("<div style='color: Black; font-weight: bold;'>" + t856 + "</div> "));
            footer["p856"].Controls.Add(new LiteralControl("<div style='color: Black; font-weight: bold;'>" + p856 + "</div> "));
            footer["t810"].Controls.Add(new LiteralControl("<div style='color: Black; font-weight: bold;'>" + t810 + "</div> "));
            footer["p810"].Controls.Add(new LiteralControl("<div style='color: Black; font-weight: bold;'>" + p810 + "</div> "));
        }

The problem I am having occurs when I expand or collapse a column the event doesn't fire and my footer is not reloaded. When I re-order the fields of the grid or using paging the footer is reloaded just fine. Any suggestions would be most helpful.

Thanks!

2 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 19 Aug 2010, 03:43 PM
Hello Shane,

The described behavior is expected because the ItemDataBound event is fired only when the grid binds to data.
To implement the desired functionality, I suggest that you keep a reference to the GridFooterItem and update its content when necessary.

Please, give this approach a try 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
0
Shane
Top achievements
Rank 1
answered on 19 Aug 2010, 04:41 PM
Thank you for your reply. I ended up using aggregates to accomplish what I was trying to do. I was able to do the the formatting and calculations in the HTML using various Column properties. For the more complex calculations I used a Custom Aggregate and used the OnCustomAggregate Event.

<telerik:GridBoundColumn HeaderText="% of 855's Rec" Aggregate="Custom" AllowSorting="true" DataFormatString="{0:P0}" FooterAggregateFormatString="{0:P0}"  DataField="Percent855" SortExpression="Percent855" UniqueName="p855"><ItemStyle HorizontalAlign="right" /><FooterStyle HorizontalAlign="right" Font-Bold="true" /></telerik:GridBoundColumn>

protected void rGridReporting_CustomAggregate(object sender, GridCustomAggregateEventArgs e)
        {
            var poList = getPurchaseOrders(null);
            var totalPos = poList.Count;
            var total855 = poList.Count(purchaseOrder => purchaseOrder.Rec855Date != null);
            var totalPos856 = poList.Count(purchaseOrder => purchaseOrder.FirstReceipt != null);
            var total856 = poList.Count(purchaseOrder => purchaseOrder.FirstReceipt != null && purchaseOrder.Rec856Date != null);
            var total810 = poList.Count(purchaseOrder => purchaseOrder.Rec810Date != null);
 
            switch (e.Column.UniqueName)
            {
                case "p855":
                    var percent855 = (decimal)total855 / totalPos;
                    e.Result = percent855;
                    break;
                case "p856":
                    var percent856 = (decimal)total856 / totalPos856;
                    e.Result = percent856;
                    break;
                case "p810":
                    var percent810 = (decimal)total810 / totalPos;
                    e.Result = percent810;
                    break;
            }
        }

This would return the correct value based on the unique name of the column. Cheers to anyone this helps!

Thanks Again Telerik Admin!
Tags
Grid
Asked by
Shane
Top achievements
Rank 1
Answers by
Mira
Telerik team
Shane
Top achievements
Rank 1
Share this question
or