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

[Solved] How do I handle Nulls in FooterTemplate for Grid control

2 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
william
Top achievements
Rank 1
william asked on 23 Jun 2011, 10:33 AM
Hi,

I have the following defined  as part of the Grid Control:

.....Columns(columns =>
              {
                  columns.Bound(r => r.CBCoverType).Title("Cover");
                  columns.Bound(r => r.SumInsured)
                      .Aggregate(aggregates => aggregates.Sum())
                      .FooterTemplate(@<text>Sum Insured: @item.Sum.Format("{0}")</text>);......

The Footer works fine when there are values in the SumInsured, but if r.SumInsured = NULL then FooterTemplate Fails, how do I code for this.

Thamks

2 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 27 Jul 2011, 09:19 PM
I have the same issue with Aggregates when data is null. In ajax mode, the "reload" image rotate infinity. I see the error with firebug ( The error is "Sum is not defined").

Any fix when the data is null?

Thanks.
0
Ed
Top achievements
Rank 2
answered on 20 Jul 2012, 05:42 PM
I found an answer 

http://www.telerik.com/community/forums/aspnet-mvc/grid/footertemplate-crash-on-empty-grid.aspx 


 .FooterTemplate(@<text>Count: @String.Format("{0}", item.Count)</text>);


seems to handle integer values.

when I try String.Format with a field that is defined at "Money" decimal the currency formatting is ignored. ie


The following crashes when sum is zero.

 columns.Bound(o => o.Amount).Aggregate(aggr => aggr.Sum())
                    .FooterTemplate(@<text>Amount Sum: @item.Sum.Format("{0:c}") </text>); 

Using String function the currency formatting is ignored, but it does not crash.

 columns.Bound(o => o.Amount).Aggregate(aggr => aggr.Sum())
                   .FooterTemplate(@<text>Amount Sum: @String.Format("{0:c}, item.Sum") </text>);
Tags
Grid
Asked by
william
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Ed
Top achievements
Rank 2
Share this question
or