Approved
Last Updated: 16 Mar 2017 08:27 by Yehudah
Yehudah
Created on: 02 Mar 2017 10:49
Category: PivotGrid
Type: Feature Request
0
PivotGrid: Group nodes into folders by Displayattribute.GroupName
I implemented it for me, but I will be glad to get it out of the box for all providers.

public class ExtendableLocalDataSourceFieldDescriptionsProvider : LocalDataSourceFieldDescriptionsProvider
{
    protected override ContainerNode GetFieldDescriptionHierarchy(IEnumerable<IPivotFieldInfo> fieldInfos)
    {
        var root = base.GetFieldDescriptionHierarchy(fieldInfos);
        var childs = from node in root.Children
                        let info = node.GetFieldInfoNode()
                        let dispAtt = info.FieldInfo.GetDisplayAttribute()
                        let groupName = dispAtt.GetGroupName()
                        where !string.IsNullOrEmpty(groupName)
                        group node by groupName into g
                        select new
                        {
                            g.Key,
                            g
                        };

        foreach (var group in childs.Reverse())
        {
            var newFolder = new ContainerNode(group.Key, ContainerNodeRole.Folder);
            foreach (var item in group.g)
            {
                root.Children.Remove(item);
                newFolder.Children.Add(item);
            }
        }
        return root;
    }

Note: GetFieldInfoNode & GetDisplayAttribute are extension methods.
0 comments