This is a migrated thread and some comments may be shown as answers.

Select last item inside node

1 Answer 392 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Tayger
Top achievements
Rank 1
Iron
Tayger asked on 29 Jun 2017, 10:21 PM

Hello there

I'm wondering if it is possible to select the last item inside a node. Example:

A +             (main node)
   A1 +        (child node of A)
   A2 +        (child node of A)
B +             (main node)

The plus sign (icon) behind each item is kinda an add item functionality inside that node. F.e. if I click on the + behind the A it would create a child item inside its node, in this case A3 + :

A +            (clicked on the +)
   A1 +
   A2 +
   A3 +      (new item created)
B +

That works fine. What I want now after creating a newitem that way is to SELECT (jump) the newly created item:

A +
   A1 +
   A2 +
   A3 +    (item is selected)
B +

I'm aware of this: treeview.select(".k-item:last");

In my case it would jump to B + (always to the end of the very last item. Can I somehow (easily) restrict the "last" so it would jump to the last element inside the node I have added a new item?

Regards

1 Answer, 1 is accepted

Sort by
0
Tayger
Top achievements
Rank 1
Iron
answered on 30 Jun 2017, 11:27 PM

Found a solution, no answer required (except there is a way easier one ;) ):

// Get the selected item in which the new item will be created
var dialogTree = $("#dialogtreediv").data("kendoTreeView");
var selectItem = dialogTree.select();
var dialogItem = dialogTree.dataItem(selectItem);
 
// Find the UID of the new item inside the selected node
var newItemUid = $("li[data-uid='"+dialogItem.uid+"'] ul > li:last").attr('data-uid');
// Select the newly item
dialogTree.select(dialogTree.findByUid(newItemUid));

 

Tags
TreeView
Asked by
Tayger
Top achievements
Rank 1
Iron
Answers by
Tayger
Top achievements
Rank 1
Iron
Share this question
or