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

set selected node using angular.

4 Answers 266 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kake
Top achievements
Rank 1
Kake asked on 14 Oct 2015, 10:54 AM

Works fine using jQuery.. 

var treeview = $("#treeview").data("kendoTreeView");
var bar = treeview.findByText("bar");
treeview.select(bar)

not sure how to do it the "angular way"​

4 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 15 Oct 2015, 06:24 AM
Hi Kake,

You will still have to find the corresponding item and use the select method, but you can use the following approach:
Please examine the dojo example and see if it meets your requirements.


Regards,
Konstantin Dikov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Kake
Top achievements
Rank 1
answered on 16 Oct 2015, 08:12 AM

Thanks for the reply.
 Not sure where I Fu#% up..
When I do the $scope.tree.findByText(nodeTekst))
it returns “[]” (have testet multiple strings I know match the tekst(s) in the nodes )
I try to select the root node if node is selected in the databound event of the tree.

some code..

<!-- Tree Init -->
<div kendo-tree-view="tree" id="tree" k-data-source="treeData" k-options="treeOptions">
   <span k-template>
      <i class="fa fa-folder-open" ng-hide="{{!dataItem.expanded}}"></i>
      <i class="fa fa-folder" ng-hide="{{dataItem.expanded}}"></i>
      {{dataItem.text}}
   </span>
</div>

 

var onDatabound = function (e) {
    if ($.isEmptyObject($scope.selectedNode)) {
        debugger;
        var item = $scope.tree.findByText(containerId);
        $scope.tree.select(item);
    }
};
 
var setSelected = function (e) {
    $scope.selectedNode = e.sender.dataItem(e.node);
    $scope.gridOptions.dataSource.data([]);
    $scope.gridOptions.dataSource.read();
    $scope.$apply();
};
 
$scope.treeOptions = {
    select: setSelected,
    dataBound: onDatabound
};

+++

 

 

 

0
Accepted
Konstantin Dikov
Telerik team
answered on 20 Oct 2015, 07:12 AM
Hello Kake,

When you are using template, the findByText method will not work, because it relies on the content of the item to find. For finding the correct item and select it you could manually traverse the items collection and using the dataItem, compare the text value:
$scope.onDatabound = function (e) {
    if ($.isEmptyObject($scope.selectedNode)) {
        var item;
        var items = e.sender.items();
        for (var i = 0; i < items.length; i++) {
            if (e.sender.dataItem(items[i]).text == containerId) {
                item = items[i];
                break;
            }
        }
        e.sender.select(item);
    }
};

Hope this resolves the issue on your side too.


Regards,
Konstantin Dikov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Kake
Top achievements
Rank 1
answered on 22 Oct 2015, 08:03 AM

Had to "manually" trigger the selected event, now it works ! (e.sender.trigger( 'select', {node: item} );)

 

Tnx!

Tags
TreeView
Asked by
Kake
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Kake
Top achievements
Rank 1
Share this question
or