Treeview total count

4 posts, 0 answers
  1. Bastian
    Bastian avatar
    9 posts
    Member since:
    May 2014

    Posted 05 Dec 2014 Link to this post

    Hello,

    I'm a bit confused about how to determine the total count of all nodes.
    Using kendo with angular it seems if I remove a parent node the total() takes the childs into account after the remove-action.

    Its simple reproducable by inserting a simple statement in Teleriks angular-example on http://kendo-labs.github.io/angular-kendo/#/TreeView

    Please insert the markup within the h3-tags where you want inside the ng-controller: <h3>{{treeData.total()}}</h3>

            <div class="sidepane" ng-show="selectedItem">
              Selected: {{selectedItem.text}}
              <br /><br />
              <button class="k-button" ng-click="addAfter(selectedItem)">Add after</button>
              <button class="k-button" ng-click="addBelow(selectedItem)">Add below</button>
              <button class="k-button" ng-click="remove(selectedItem)">Delete</button>
              <h3>{{treeData.total()}}</h3>
            </div>


    take this action:
    - run code/markup
    - select node 'item 3'
    - first unexprected behaviour: displayed total() takes childs NOT into account (number is 3 instead 5)
    - click button 'Add below' (e. g. 5 times)
    - click delete and remove all parents (dont delete the childs explicit)
    - result: the displayed total() is > 0 (e. g. 5 if clicked 3 times on 'Add below')

    So here my question: how to determine the true number of currently existing nodes? Perhaps its obvious for somebody. For me its not - im fightig to the same time with angular and with kendo, because both is new to me.
    Thanks a lot.


  2. Mihai
    Admin
    Mihai avatar
    153 posts

    Posted 09 Dec 2014 Link to this post

    Hi,

    It seems total() is buggy for the case of HierarchicalDataSource.  I filed an internal report about this.  Until it's fixed, you can count items with a helper function.  See this sample.

    This is the function that does it:

          function countNodes(tree) {
            var total = 0;
            tree = tree.data();
            for (var i = 0; i < tree.length; ++i) {
              var el = tree[i];
              if (el.hasChildren) {
                total += countNodes(el.children);
              }
              total++;
            }
            return total;
          }

    Also, note that I had to pass loadOnDemand: false to the tree widget (via k-load-on-demand attribute), so that all data is present initially, even though the tree is collapsed.

    Regards,
    Mihai
    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. Bastian
    Bastian avatar
    9 posts
    Member since:
    May 2014

    Posted 10 Dec 2014 in reply to Mihai Link to this post

    Hello and thank you.
    A similar function I wrote myself to bypass the problem. I'm curios, when the related fix will hit the release version.
  5. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 12 Dec 2014 Link to this post

    Hello,

    We're discussing this issue, but we can't commit on a resolution for the moment.

    The HierarchicalDataSource is actually a "data source of data sources" of sorts.
    This makes tasks such as filtering, calculating totals and so on quite tricky.

    It's unclear how the total should be calculated when using virtualization for example.
    In this case all data sources will share the same server endpoint. It's not trivial to return the right count from the server.

    We're still not decided on what the best approach would be, but a short-term fix is unlikely at this point.
    Apologies for the caused inconvenience.

    Regards,
    T. Tsonev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready