Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve Bentley 21 posts 64 karma points
    Jun 07, 2016 @ 07:51
    Steve Bentley
    0

    Multi-level tree controllers

    Hi,

    I'm creating a plugin package that needs to list out items in the tree view in the backend. The items it needs to display are not Umbraco content nodes, but are loaded directly from the database.

    I've got it working adding items at the top level of the tree view under a root item, but I want to be able to add multi-level "folders" that can contain other "folders" or items.

    Does anyone now a good way to set up a TreeController to allow nesting of items?

    Thanks

    Steve

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 07, 2016 @ 08:53
    David Brendel
    0

    Hi Steve,

    the common way is to check the id of the node which is opened and regarding to that id return the child nodes.

    That is looking something like that:

    if (id == global::Umbraco.Core.Constants.System.Root.ToInvariantString())
            {
                var tree = new TreeNodeCollection();
                tree.Add(CreateTreeNode("calendarTree", id, queryStrings, "Calendar", "icon-calendar-alt", true, FormDataCollectionExtensions.GetValue<string>(queryStrings, "application") + StringExtensions.EnsureStartsWith(this.TreeAlias, '/') + "/overviewCalendar/all"));
                }
                return tree;
            }
    
            if (id == "calendarTree")
            {
                var tree = new TreeNodeCollection();
    
                List<ECalendar> calendar = new List<ECalendar>();
    
                if (Security.CurrentUser.UserType.Alias.ToLower() == "admin")
                {
                    calendar = CalendarService.GetAllCalendar().ToList();
                }
                else
                {
                    calendar = CalendarService.GetCalendarForUser(Security.GetUserId()).ToList();
                }
                foreach (var cal in calendar)
                {
                    tree.Add(CreateTreeNode("c-" + cal.Id.ToString(), id, queryStrings, cal.Calendarname, "icon-calendar", true, FormDataCollectionExtensions.GetValue<string>(queryStrings, "application") + StringExtensions.EnsureStartsWith(this.TreeAlias, '/') + "/editCalendar/" + cal.Id));
                }
                return tree;
            }
    

    Thas just copy paste from a package I develop but I hope it gets you the idea. The calendar are loaded from a service directly from the database.

    Regards David

Please Sign in or register to post replies

Write your reply to:

Draft