foreach
(DateTime date
in
this
.VisibleWeeks)
{
var source = String.Format(
"WeeklyEstimates[{0}].Hours"
, i);
var dataBinding =
new
Binding(source);
dataBinding.Mode = BindingMode.TwoWay;
dataBinding.UpdateSourceTrigger = UpdateSourceTrigger.Default;
GridViewDataColumn column =
new
GridViewDataColumn
{
UniqueName = date.ToString(),
DataMemberBinding = dataBinding,
Header = date.ToShortDateString(),
IsFilterable =
false
,
TextAlignment = TextAlignment.Center,
};
column.AggregateFunctions.Add(
new
SumFunction() { SourceField = source });
ResourceEstimateGrid.Columns.Add(column);
i++;
}
Any suggestions on what I'm doing wrong? Thanks.
13 Answers, 1 is accepted
Actually, I can see nothing that may be causing the issue you described. Is the column filled properly with values ? Do you get any exceptions ? Is this behavior for all columns or only for those numeric ones ? What is the structure of you business object - do you have all the properties exposed that are used for calculating the aggregates?
Generally, any further relevant information or code-snippet would be helpful in resolving the case.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
When I define the column in the Xaml, the SumFunction works as intended.
<
telerik:GridViewDataColumn
Header
=
"Today"
DataMemberBinding
=
"{Binding WeeklyEstimates[0].Hours}"
IsFilterable
=
"False"
>
<
telerik:GridViewDataColumn.AggregateFunctions
>
<
telerik:SumFunction
/>
</
telerik:GridViewDataColumn.AggregateFunctions
>
</
telerik:GridViewDataColumn
>
However, if I define another column with the exact same Binding in the code-behind, the SumFunction doesn't do anything.
private
void
AddColumns()
{
DateTime[] visibleWeeks =
new
[]{
DateTime.Today,
DateTime.Today.AddDays(7)
};
int
index = 0;
foreach
(DateTime date
in
visibleWeeks)
{
String source = String.Format(
"WeeklyEstimates[{0}].Hours"
, index);
Binding binding =
new
Binding(source);
binding.Mode = BindingMode.TwoWay;
binding.UpdateSourceTrigger = UpdateSourceTrigger.Default;
GridViewDataColumn column =
new
GridViewDataColumn()
{
UniqueName = date.ToString(),
DataMemberBinding = binding,
Header = date.ToShortDateString(),
IsFilterable =
false
,
};
column.AggregateFunctions.Add(
new
SumFunction() { SourceField = source });
ResourceEstimateGrid.Columns.Add(column);
index++;
}
}
As you can see in the screen shot, my "Today" column is summed up at the bottom, but my 2 dynamic columns are not.
Thanks for your help.
- Bob
I finally managed to reproduce the issue and we are currently researching the cause of it. I will let you know as soon as we have more information about it.
Thank you for you patience and cooperation.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
http://www.telerik.com/community/forums/silverlight/gridview/radgrid-export-to-excel-unable-to-maintain-decimal-format-for-number-less-than-4-digits.aspx
Any word on this issue?
We are still investigating the issues as changing the default behavior (as it is right now) might lead to some performance degradation which is definitely an undesired result. Generally, our concern is that recalculating the aggregates on inserting a new column may require a heavy calculating operation, which on the other side will need all the data from the data base.
Would it be possible for your exact scenario and settings to call CalculateAggregates() method of the grid:
private void AddColumns()
{
DateTime[] visibleWeeks = new[]{
DateTime.Today,
DateTime.Today.AddDays(7)
};
int index = 0;
foreach (DateTime date in visibleWeeks)
{
String source = String.Format("WeeklyEstimates[{0}].Hours", index);
Binding binding = new Binding(source);
binding.Mode = BindingMode.TwoWay;
binding.UpdateSourceTrigger = UpdateSourceTrigger.Default;
GridViewDataColumn column = new GridViewDataColumn()
{
UniqueName = date.ToString(),
DataMemberBinding = binding,
Header = date.ToShortDateString(),
IsFilterable = false,
};
column.AggregateFunctions.Add(new SumFunction() { SourceField = source });
ResourceEstimateGrid.Columns.Add(column);
index++;
}
ResourceEstimateGrid.CalculateAggregates();
}
Will that approach result in the desired behavior ?
Greetings,
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I added the call to CalculateAggregates() after the foreach loop as you suggested, but the totals are still not showing up. This would be acceptable in my scenario if it worked, as this data calculation isn't too intensive, but unfortunately it doesn't seem to resolve the issue.
Thanks,
Bob
Would you take a look at the sample attached and let me know whether it corresponds to your scenario ? Can you reproduce the same behavior on it ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Sorry it has taken me so long to respond, this project got pushed aside for a while.
I was able to replicate the issue in the project you included by doing the following:
- Setting ShowGroupFooters="True" on the RadGridView.
- Added a GroupDescriptor on the Grid, and grouping by Name
If you do that, you'll see that the footer at the bottom of the page will still show the aggregate values, but the group footers will not.
Please let me know if you need more information.
Thanks,
Bob
Actually, in this case it would be the expected behavior as the group aggregates are not recalculated. You will need to refresh the source:
private void Button1_Click(object sender, RoutedEventArgs e)
{
Binding binding = new Binding("Name");
binding.Mode = BindingMode.TwoWay;
binding.UpdateSourceTrigger = UpdateSourceTrigger.Default;
GridViewDataColumn column = new GridViewDataColumn()
{
DataMemberBinding = binding,
IsFilterable = false
};
column.AggregateFunctions.Add(new CountFunction());
this.clubsGrid.Columns.Add(column);
this.clubsGrid.Columns[2].AggregateFunctions.Add(new SumFunction());
this.clubsGrid.CalculateAggregates();
this.clubsGrid.Rebind();
}
Greetings,
Maya
the Telerik team
I tried calling Rebind() as you mentioned, but it didn't seem to fix the issue. The group aggregates are still showing as blank.
Do you have any other suggestions? Is there any way I can send you my current solution so you can reproduce the issue?
Thanks,
Bob
Indeed, you are quite correct - I have retested the case when a group descriptor is created in advance and an aggregate is added. We will research the issue and let you know once we have more information on the topic.
Thank you for your patience.
Maya
the Telerik team
We are still investigating the issue in attempt to find the most appropriate solution so that no breaking changes are introduces. In the meantime, I would recommend you to work with ColumnGroupDescriptor (not GroupDescriptor) and add/ replace the aggregates of a column.
Let me know in case you need assistance with the implementation.
Maya
the Telerik team