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

Treeview total count

3 Answers 627 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bastian
Top achievements
Rank 1
Bastian asked on 05 Dec 2014, 11:36 AM
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.


3 Answers, 1 is accepted

Sort by
0
Mihai
Telerik team
answered on 09 Dec 2014, 12:16 PM
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!
 
0
Bastian
Top achievements
Rank 1
answered on 10 Dec 2014, 07:30 AM
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.
0
T. Tsonev
Telerik team
answered on 12 Dec 2014, 08:58 AM
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!
 
Tags
TreeView
Asked by
Bastian
Top achievements
Rank 1
Answers by
Mihai
Telerik team
Bastian
Top achievements
Rank 1
T. Tsonev
Telerik team
Share this question
or