Sometimes, when a business class has a lot of properties, it is not suitable to have all of them in the Filter Area. This example demonstrates how to place fields into the Field List popup window by default. To do this, the AreaIndex property of the generated fields is set to -1, which means that these fields do not belong to any area. This is done via a custom field builder - CustomPivotFieldBuilder. This class is used by XAF to generate PivotGrid fields. Generated fields are modified in the field builder's AddFieldCore method. In this example, a custom field builder is assigned to the analysis editor via its FieldBuilder property in the HidePivotGridFieldsControllerBase controller. This solution is platform-independent, i.e. the same code works for both WinForms and ASP.NET.
Question Comments
Added By: Tony Tadros at: 1/27/2014 8:57:23 AM
Hello Devexpress ,
had a query about this scenario
what if i want to present the full list of fields (default ) when user is first creating the analysis object ,after user specify what fields he want to use
next time he opens the analysis it will hide the rest of the fields as your example here
my question is how to understand if the pivot settings is blank or not so i can trigger the above code
Added By: Anatol (DevExpress Support) at: 1/28/2014 1:18:13 AMI have created a ticket for this question on your behalf and will post my answer there: https://www.devexpress.com/Support/Center/Question/Details/Q466013
Added By: HAKAN BIYIKLIOGLU at: 2/11/2015 6:31:12 PMHello,
Here's a little modification to add all the fields from all subclasses in the binding datatype.
Using recursion to accomplish this. Please feel free to advance and share.
public CustomPivotFieldBuilder(IAnalysisControl owner) : base(owner) { }
protected override void AddFieldCore(
string caption,
string bindingPropertyName,
DevExpress.ExpressApp.DC.IMemberInfo propertyDescriptor)
{
if (Owner.Fields[bindingPropertyName] == null)
{
base.AddFieldCore(caption, bindingPropertyName, propertyDescriptor);
if (bindingPropertyName == "Oid")
{
// Add the Oid field to DataArea so the pivot will not appear empty on first bind
Owner.Fields[bindingPropertyName].Area = PivotArea.DataArea;
Owner.Fields[bindingPropertyName].Caption = "Number";
}
else
// Hide the field
Owner.Fields[Owner.Fields.Count - 1].AreaIndex = -1;
if (propertyDescriptor.MemberType.IsSubclassOf(typeof(BaseObject)))
{
Type internalTargetType = propertyDescriptor.MemberType;
XPClassInfo ci = XpoTypesInfoHelper.GetXpoTypeInfoSource().XPDictionary.GetClassInfo(internalTargetType);
TypeInfo memberTypeInfo = XafTypesInfo.Instance.FindTypeInfo(ci.ClassType) as TypeInfo;
foreach (IMemberInfo m in memberTypeInfo.OwnMembers)
{
if (m.IsPublic && m.IsProperty && !m.IsAssociation && m.IsPersistent && !m.IsAliased && !m.IsDelayed &&
// Preventing circular class references below
m.MemberType.FullName != memberTypeInfo.FullName)
{
AddFieldCore(
CaptionHelper.GetMemberCaption(propertyDescriptor) + "-" +
(string.IsNullOrEmpty(CaptionHelper.GetMemberCaption(m)) ? m.Name : CaptionHelper.GetMemberCaption(m)),
propertyDescriptor.Name + "." + GetBindingName(m),
propertyDescriptor);
}
}
}
}
}