Hi there,
I've been searching and reading for 2 days now and I've some doubts about the TreeView that I need to clarify.
1. The tree will have three levels of deep
+ Contenedor "zst"
|
| --- Bulto 1. Largo: 2.6 Ancho: 3.6 Alto: 5.3
| |
| --- Producto: "Table" Cantidad: 32
| --- Producto: "Computer" Cantidad: 25
|
| --- Bulto 2. Largo: 1.3 Ancho: 8.3 Alto: 2.2
| |
| --- Producto: "Mouse" Cantidad: 8
| --- Producto: "Keyboard" Cantidad: 7
|
+ Contenedor "trx"
|
|
--- Bulto 1. Largo: 4.2 Ancho: 13.1 Alto: 15.7
|
--- Producto: "Display" Cantidad: 7.7
--- Producto: "Battery" Cantidad: 2.3
What follows are questions that I don't have answers so far and I don't know whether it's possible to achieve using this widget
1. I need to apply a different template to every level:
a) In the first level (Contenedor) I need to show the word "Contenedor" plus a string specified by the user
b) In the second level (Bulto) I need to show the word "Bulto" plus "Largo" followed by a number then the word "Ancho" followed by a number and the word "Alto" followed by a number
c) In the third level (Producto) I need to show the word "Producto" plus a string then the word "Cantidad" followed by a number
2. In every level of the tree the user can edit the values:
a) In the first level (Contenedor) the user can change the description (a string)
b) In the second level (Bulto) the user can change the "Largo" (decimal), "Ancho" (decimal) and "Alto" (decimal)
c) In the third level (Producto) the user can change "Cantidad" (decimal).
3. The TreeView must support drag & drop between it and a Grid widget so the user can drop the items from the tree in the grid and items from the grid in the Tree.
4. How do I get the model associated to a node in the Tree? If possible I would like to keep in the datasource the same members of the classes defined in the backend for each node in the Tree. I.e.
When I get the model of a node in the second level (Bulto) I would like to get this in the JavaScript object:
{ ID: 1, NumeroBulto: 2, Largo: 43, Ancho: 23.3, Alto: 2.1, Volumen: 4.2,}
Instead of the TreeViewItem object.
Here's my model
01.public class TreeModel02. {03. public List<ContenedorModel> Contenedores { get; set; }04. }05. 06. public class ContenedorModel07. {08. public Guid ID { get; set; }09. public string Descripcion { get; set; }10. public List<BultoModel> Bultos { get; set; }11. }12. 13. public class BultoModel14. {15. public Guid ID { get; set; }16. public int NumeroBulto { get; set; }17. public decimal Largo { get; set; }18. public decimal Ancho { get; set; }19. public decimal Alto { get; set; }20. public decimal Volumen { get; set; }21. public List<ProductoTreeModel> Productos { get; set; }22. }23. 24. public class ProductoTreeModel25. {26. public Guid ID { get; set; }27. public string Descripcion { get; set; }28. public decimal Cantidad { get; set; }29. }
Here's my view
01.@(Html.Kendo().TreeView()02. .Name("treeView")03. .TemplateId("treeview-template-contenedor")04. .BindTo((IEnumerable<ContenedorModel>)Model.TreeModel.Contenedores, (NavigationBindingFactory<TreeViewItem> mappings) =>05. {06. mappings.For<ContenedorModel>(binding => binding.ItemDataBound((item, contenedor) =>07. {08. item.Text = $"Contenedor: {contenedor.Descripcion}";09. })10. .Children(x => x.Bultos));11. 12. mappings.For<BultoModel>(binding => binding.ItemDataBound((item, bulto) =>13. {14. item.Text = $"Bulto: {bulto.NumeroBulto}";15. })16. .Children(x => x.Productos));17. 18. mappings.For<ProductoTreeModel>(binding => binding.ItemDataBound((item, producto) =>19. {20. item.Text = producto.Descripcion;21. }));22. })23. .DragAndDrop(true)24.)
Here's the template
1.<script id="treeview-template-contenedor" type="text/kendo-ui-template">2. <span style="color:blue">#: item.Text #</span>3. <button><span class='k-icon k-edit' /></button>4.</script>
However the way I use the template here is applied to all levels.
Can anyone please help me with this?
Thank you.
