Hello Telerik,
I linked a radPivotFieldList with a radPivotGrid. All of my radPivotFieldList's Controls used the CustomName expect the FieldList.
Is there any way to use Custom Name instead of Property Name ?
I try this code too but it doesn't work
radPivotFieldList1.FieldsControl.Nodes[0].RootNode.Text="my text0";
Finally I try to remove a Node and adding another but it doesn't work because of the FielList is automaticaly updating after :
Telerik.WinControls.UI.RadTreeNode test = new RadTreeNode(){Value =radPivotFieldList1.FieldsControl.Nodes[0].Value, Text="test" } ;
radPivotFieldList1.FieldsControl.Nodes.Remove(radPivotFieldList1.FieldsControl.Nodes[0]);
radPivotFieldList1.FieldsControl.Nodes.Add(test);
Best regards
11 Answers, 1 is accepted
Thank you for contacting us.
We have already logged this issue in our Feedback Portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - FIX. RadPivotFieldList - does not display CustomName if field is removed and added again.
Currently I can suggest you to subscribe to the FieldsControl.NodeFormatting, RowLabelsControl.VisualItemFormatting and ColumnLabelsControl.VisualItemFormatting events and change the displayed text. Here is the code snippet:
void
ColumnLabelsControl_VisualItemFormatting(
object
sender, Telerik.WinControls.UI.VisualItemFormattingEventArgs args)
{
var data = args.VisualItem.Data.DataBoundItem
as
Telerik.WinControls.UI.PivotFieldList.IField;
if
(data !=
null
&& data.FieldInfo.Name ==
"OrderID"
)
{
((RadItem)args.VisualItem.Children[0]).Text =
"Order ID"
;
}
}
void
RowLabelsControl_VisualItemFormatting(
object
sender, Telerik.WinControls.UI.VisualItemFormattingEventArgs args)
{
var data = args.VisualItem.Data.DataBoundItem
as
Telerik.WinControls.UI.PivotFieldList.ILabel;
if
(data !=
null
&& data.FieldInfo.Name ==
"OrderID"
)
{
((RadItem)args.VisualItem.Children[0]).Text =
"Order ID"
;
}
}
void
FieldsControl_NodeFormatting(
object
sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
{
if
(e.Node.Text ==
"OrderID"
)
{
e.NodeElement.ContentElement.Text =
"Order ID"
;
}
}
In the attachment you can find a sample demo and video which demonstrates the approach.
I hope this will help. Do not hesitate to write back with further questions.
Regards,
Ralitsa
Telerik
Hi Ralitsa.
Thanks for your answer.
It well works, i hope it could be automatised soon.
Best regards
Hi Ralitsa,
I've got the same problem with the radpivotgrid Associated. can you tell me events to suscribe ?
Best regards
Thank you for your reply.
You can subscribe to the DataProvider.PrepareDescriptionForField event and set the CustomName property. Here is the code snippet:
private
void
DataProvider_PrepareDescriptionForField(
object
sender, PrepareDescriptionForFieldEventArgs e)
{
if
(e.Description.DisplayName ==
"ShipCity"
)
{
e.Description =
new
PropertyGroupDescription() { PropertyName = e.Description.DisplayName, GroupComparer =
new
GrandTotalComparer(), CustomName =
"Ship City"
};
}
}
In the attachments you can find the modified project.
I hope this will help you. Let me know if you have any other questions.
Regards,
Ralitsa
Telerik
Hi Ralitsa.
Thanks for your answer.
I attach on the GroupDescriptorElementCreating event and it works
Best regards
I am glad to hear that everything works fine for you now. Do not hesitate to write back if you have additional questions.
Regards,
Ralitsa
Telerik
Hi,
I've got a new question. How do you change the stringformat of an aggregateDescriptor created by user ? In fact, when users use the radpivotfield to define an aggregate descriptor, I attach myself to the AggregateDescriptorElementCreating event. But i don't find how to access to the stringFormat.
I hope someone got the solution.
Best regards
Thank you for contacting us.
You can refer to the following code snippet demonstrating how to change StringFormat property of the AggregateDescriptor in the handler of the AggregateDescriptorElementCreating event:
void
radPivotGrid1_AggregateDescriptorElementCreating(
object
sender, Telerik.WinControls.UI.AggregateDescriptorElementCreatingEventArgs e)
{
PropertyAggregateDescription agg = (PropertyAggregateDescription)e.AggregateDescriptorElement.AggregateDescriptor;
if
(agg.PropertyName ==
"OrderID"
)
{
agg.StringFormat =
"C2"
;
}
}
I hope this will help. Do not hesitate to write back with further questions.
Regards,
Ralitsa
Telerik
Hi Ralitsa,
Thanks for your answer, it's well works.
Best regards
Ralitsa, your solution worked for providing a custom name in the Field List, but after doing that, my fields are not sorted ascending anymore.
Here is a code snippet:
this.provider = new LocalDataSourceProvider() { ItemsSource = gridData };
this.radPivotFieldList1.FieldsControl.SortOrder = System.Windows.Forms.SortOrder.Ascending;
Somewhere after this the events get fired and change the field names so that the sorting is ruined. Where do I re-sort?
The FieldsControl inside RadPivotFieldList is actually represented by a RadTreeView. It can sort its nodes via the mentioned SortOrder property: https://docs.telerik.com/devtools/winforms/controls/treeview/working-with-nodes/sorting-nodes
However, please have in mind that the nodes are sorted by the RadTreeNode.Text property, not the visual element property, e.g. not the NodeElement.ContentElement.Text in the NodeFormatting event.
However, RadTreeView supports custom sorting. Thus, you can control how the nodes are being ordered by specifying the RadPivotFieldList.FieldsControl.TreeViewElement.Comparer. A sample approach is demonstrated here: https://docs.telerik.com/devtools/winforms/controls/treeview/working-with-nodes/custom-sorting
I can suggest you to store into an appropriate data structure (e.g. a Dictionary<key,value>) the node's text and a sort order number. Thus, in the TreeNodeComparer you can extract the order index by the node's text and thus specify the sort result.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).