I tried this kind of system:
public class LoadData
{
public Guid Id { get; set; }
public Guid Parent { get; set; }
public string Text { get; set; }
public string SpriteImage { get; set; }
public string ImageURL { get; set; }
public bool HasChild { get; set; }
public bool Expanded { get; set; }
public bool Selected { get; set; }
public bool NodeChecked { get; set; }
public object NodeProperty { get; set; }
public object LinkProperty { get; set; }
public object ImageProperty { get; set; }
};
VM_TenantUserEdit vm = new VM_TenantUserEdit { TenantId = tenantId };
vm.datasource = new List<LoadData>();
Guid g1 = Guid.NewGuid();
Guid g2 = Guid.NewGuid();
Guid g3 = Guid.NewGuid();
Guid g4 = Guid.NewGuid();
Guid g5 = Guid.NewGuid();
Guid g6 = Guid.NewGuid();
Guid parent = Guid.Empty;
vm.datasource.Add(new LoadData { Id = g1, Parent = parent, Text = "Item 1" });
vm.datasource.Add(new LoadData { Id = g2, Parent = parent, Text = "Item 2" });
vm.datasource.Add(new LoadData { Id = g3, Parent = parent, Text = "Item 3" });
vm.datasource.Add(new LoadData { Id = g4, Parent = g1, Text = "Item 1.1" });
vm.datasource.Add(new LoadData { Id = g5, Parent = g1, Text = "Item 1.2" });
vm.datasource.Add(new LoadData { Id = g6, Parent = g3, Text = "Item 3.1" });
<form>
<div style="width: 250px">
@(Html.EJ().TreeView("tree")
.TreeViewFields(field =>
field.Datasource(Model.datasource)
.Id("Id")
.ParentId("Parent")
.Text("Text")
).ShowCheckbox(true))
</div>
<form>
It seems that if the keys are Guids, EJ.TreeView crashes. So building the hierarchy with other keys than integer does not work.
In addition, when used inside of a form, tree control should return the id instead of Text. In a localized sw the text can be a random string, but id is always the same.