RadPivotGrid control supports not only grouping by primitive types but it supports grouping by custom objects. By design the
PivotGrid shows grouped data which is described into its fields by setting their
DataField property. In most cases it is a primitive type (like string, integer, boolean, etc.). However you could set the
DataField of some PivotGrid field to a custom object. For example if you have a custom class
Product which has property
ProductCategory which type is another custom class
Category:
public class Product
{
...
public Category ProductCategory { get; set; }
}
You could set the
ProductCategory as DataField of the PivotGrid field and group by
Category objects:
...
<telerik:PivotGridRowField DataField="ProductCategory">
</telerik:PivotGridRowField>
...
In this case you should override the
GetHashCode,
Equals and
ToString() methods into the
CategoryClass, also you need to implement
IComparable interface and mark the class as Serializable. For example:
[Serializable] public class Category: IComparable
{
public int CategoryID { get; set; }
public string CategoryName { get; set; }
public string Description {get;set;}
public override string ToString()
{
return CategoryID.ToString() + " " + CategoryName;
}
public override bool Equals(object obj)
{
Category category = obj as Category;
if (category != null)
{
return CategoryID.Equals(category.CategoryID) &&
CategoryName.Equals(category.CategoryName) &&
Description.Equals(category.Description);
}else{
return false;
}
}
public override int GetHashCode()
{
return CategoryID.GetHashCode() + CategoryName.GetHashCode() + Description.GetHashCode();
}
public int CompareTo(object obj)
{
return CategoryID.CompareTo(((Category)obj).CategoryID);
}
}