set selected node using angular.

5 posts, 1 answers
  1. Kake
    Kake avatar
    14 posts
    Member since:
    Jan 2015

    Posted 14 Oct 2015 Link to this post

    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"​

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1796 posts

    Posted 15 Oct 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Kake
    Kake avatar
    14 posts
    Member since:
    Jan 2015

    Posted 16 Oct 2015 in reply to Konstantin Dikov Link to this post

    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
    };

    +++

     

     

     

  5. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1796 posts

    Posted 20 Oct 2015 Link to this post

    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!
     
  6. Kake
    Kake avatar
    14 posts
    Member since:
    Jan 2015

    Posted 22 Oct 2015 in reply to Konstantin Dikov Link to this post

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

     

    Tnx!

Back to Top
Kendo UI is VS 2017 Ready