3 Answers, 1 is accepted
I'm using Telerik Reporting Q3 2010 with VS 2010 and .Net Framework 4.0.
I have a report. On this report I'm adding a table. I have configured a list of my business objects as datasource.
This datasource is the datasouce of my table.
When I render this report/table all my entries are added to the table! So, it works very well!
Now I wanna have the rownumber in the first column, so I added this expression on my first column: "= RowNumber()", my second column is like "Fields.Name", third like "Fields.ID" and so on (just the properties of my business object).
My result looks like this:
RowNumber Name ID (Header-Row)
1 FooName1 1
1 FooName2 2
1 FooName3 4
So, the table will be generated, but the rownumber always says "1"!!
Is there any help or trick? Anyone?
Thank you for your advices!
Yavor:
You can simulate GroupNumber() function with the RunningValue function and CountDistinct User/Custom Aggregate Function:
= RunningValue("crosstab1",CountDistinct(Fields.Manufacturer))
User Aggregate Functions allow you to apply custom logic when accumulating values over a set of data records. They are used by the Telerik Reporting engine as all built-in aggregate functions. Check out the following code snippets that illustrates how to implement a CountDistinct aggregate:
[AggregateFunction(Name = "CountDistinct", Description = "Defines an aggregate function to count distinct values.")]
public class CountDistinctAggregate : Telerik.Reporting.Expressions.IAggregateFunction
{
private System.Collections.Generic.List<
object
> distinctValues;
/// <
summary
>
/// Initializes the current aggregate function to its initial state
/// ready to accumulate and merge values.
/// </
summary
>
/// <
remarks
>
/// This method is called every time the accumulation of values must
/// start over for a new subset of records from the data source.
/// </
remarks
>
public void Init()
{
this.distinctValues = new System.Collections.Generic.List<
object
>();
}
/// <
summary
>
/// Accumulates new argument values to the current aggregate function.
/// </
summary
>
/// <
remarks
>
/// This aggregate function accepts one argument:
/// number - a numeric value to accumulate to the aggregate function;
/// </
remarks
>
public void Accumulate(object[] values)
{
if (!distinctValues.Contains(values[0]))
{
distinctValues.Add(values[0]);
}
}
/// <
summary
>
/// Merges the specified aggregate function to the current one.
/// </
summary
>
/// <
paramname
=
"Aggregate"
>
/// Specifies an aggregate function to be merged to the current one.
/// </
param
>
/// <
remarks
>
/// This method allows the reporting engine to merge two accumulated
/// subsets of the same aggregate function into a single result.
/// </
remarks
>
public void Merge(IAggregateFunction aggregate)
{
// Accumulate the values of the specified aggregate function.
System.Collections.Generic.List<
object
> sums1 = ((CountDistinctAggregate)aggregate).distinctValues;
foreach (object o in sums1)
{
this.Accumulate(new object[] { o });
}
}
/// <
summary
>
/// Returns the currently accumulated value of the aggregate function.
/// </
summary
>
/// <
returns
>
/// The currently accumulated numeric value of the aggregate function.
/// </
returns
>
public object GetValue()
{
return this.distinctValues.Count;
}
}
Note that you may not be able to preview the report in Designer Preview.
Additionally for better understanding of the Custom Aggregates and if you want create custom ones check the Dynamic Sorting of Reporting Crosstabs Using a Custom Aggregate Function blog article.
Patrick:
We are not sure what is causing the described behavior of the RowNumber(). Generally you have to add it to a Table Detail Group in order to count the rows. If you still experience any troubles we will appreciate if you open a support thread and send us a sample runnable project that exhibits the issue to debug locally.
Peter
the Telerik team