0

I use business pack treeview component for menu. My goal is to retrieve only top level menu without subcategories. Subcategories will show only on user icon click (+ / - icons) or on menu item click.

So basically when I click on "a" or icon binded to this menu object, I want to send request to my server to get his subcategories and so on. I dont want to get everything in one request.

enter image description here

As I noticed there are two click handlers in view.

1) Use Changedproperty - when I use this property to handle click events, I successfully get correct object into my CategorySelectedList, but it only register clicks directly on text label. For icon it doesnt work anymore and also category menu will not expand.

2) Use Events.Clickproperty - when I use this property to handle click events. I dont even get correct object into my CategorySelectedList property, but category menu will expand in this case.

I cant send object Id from my view into SetActiveMenuNode method so I have to take it directly from my CategorySelectedList but each aproach has his own problems.

Is there any solution for this?

ModelView

public List<CategoryListDTO> AdminMenuList { get; set; } = new List<CategoryListDTO>();
public List<CategoryListDTO> AdminMenuSelectedList { get; set; } = new List<CategoryListDTO>();
public void SetActiveMenuNode()
{
    var selected = AdminMenuSelectedList.FirstOrDefault();
}

//načítání podkategorií 
public StaticCommandBindingExpression LoadChildren { get; set; } = new StaticCommandBindingExpression(new CompiledBindingExpression( //something here));  

My view

<dot:Content ContentPlaceHolderID="MainContent">
<section class="content">
    <bp:TreeView DataSource="{value: AdminMenuList}"
                 SelectedValues="{value: AdminMenuSelectedList}"
                 ItemKeyBinding="{value: Id}"
                 ItemHasChildrenBinding="{value: HasCategories}"
                 ItemChildrenBinding="{value: AssignedToCategory}"
                 LoadChildren="{staticCommand: _parent.MyMethod()}"
                 Changed="{command: SetActiveMenuNode()}"          
                 >
        <p>{{value: Name}}</p>
    </bp:TreeView>
</section>

Martin
  • 455
  • 1
  • 11
  • 34

1 Answers1

1

Unfortunately there is no solution right now. We have this feature in our backlog and will implement it when possible.

We have implemented this feature in version 1.1.5-rc1. The TreeView control has a new property LoadChildren of type StaticCommandBindingExpression. Here is an example on how to use it.

ViewModel.cs

[AllowStaticCommand]
public static IEnumerable<Item> LoadChildren(Item parent)
{
    return LoadYourChildrenFromSomewhere(parent.Id);
}

View.dothtml

<bp:TreeView LoadChildren="{staticCommand: ViewModel.LoadChildren(_this)}" />

Please note that DI is not yet supported for static commands (it's coming). You need to create the required services yourself or resolve them from global service provider.

Dusan Janosik
  • 296
  • 3
  • 11
  • I have a good news for you. This feature will be available in next beta version. – Dusan Janosik Aug 02 '17 at 10:03
  • Thanks for information. When the next beta version should be released? – Martin Aug 02 '17 at 20:22
  • We have released version 1.1.5-rc1 where this feature is included. – Dusan Janosik Aug 09 '17 at 20:52
  • Thanks for info, gonna try as soon as possible. Upvoting and accepting answer – Martin Aug 10 '17 at 07:44
  • Take a look at `LoadChildren` command. It accepts the expanded item as argument and should return it's children / descendants. – Dusan Janosik Aug 10 '17 at 07:45
  • Is it possible to get this version via NuGet? I dont see any this version in version list. I also check your dotvvm feed and no success also. – Martin Aug 10 '17 at 08:18
  • So after visual studio restart it finally showed up in NuGet. – Martin Aug 10 '17 at 08:28
  • Updated my question. Working on it right now, if I get it right, i have to create and initialize property with type `StaticCommandBindingExpression ` and after that I have to pass that expanded item ( in my case it is my `SelectedValue` so `AdminMenuSelectedList` I guess ) but how can I pass it? Is it possible to create some sample? – Martin Aug 10 '17 at 11:32
  • I found how i can register service in `dotvvm startup`. What I cant figure out, how I can create that service for `staticCommand`. Do you have some documentation for this or if you could provide some sample I would be so grateful. – Martin Aug 10 '17 at 17:02
  • It depends on your IoC container and your app configuration. If you are using ASP.NET Core, you may find this [issue](https://github.com/aspnet/DependencyInjection/issues/294) useful. But I can't help you with that. – Dusan Janosik Aug 11 '17 at 07:37