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

TreeView expanding all nodes and thus loading entire tree

3 Answers 444 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 29 Oct 2013, 10:01 PM
I am trying to load the tree data on demand using the read and sending down id, hasChildren, and expanded - since I want to expand the root initially.  Only the root node has the expanded value true, all others have it false.

My data source is:
dataSource: new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: '/WidgetJson/OrgTree',
            type: 'POST',
            dataType: 'json',
            data: function (currentParams) {
                var params = {};
                params['includeCardAccounts'] = true;
                return params;
            }
        }
    },
    schema: {
        model: {
            id: 'OrgId',
            hasChildren: 'HasChildren',
            expanded: 'Expanded'
        }
    }
}),
dataTextField: 'OrgDescription'

and the first JSON response from the server is:
[{"OrgId":46431736,"OrgDescription":"XYZ DEPT Company","HasChildren":true,"Expanded":true}]
and this is the root item and is properly expanded in the tree view - properly reflecting the "Expanded":true.
the second JSON response from the server is (truncated for brevity):
[{"OrgId":46431761,"OrgDescription":"OPExxxxxx - Ixx","HasChildren":true,"Expanded":false},{"OrgId":46431760,"OrgDescription":"OS xxxxxx IBA","HasChildren":true,"Expanded":false},{"OrgId":46431759,"OrgDescription":"ODSxxxxxx- IBx","HasChildren":true,"Expanded":false}]
Note that the first item in this JSON object ("OPExxxxxx - Ixx") is shown with the "Expanded":false, but in the treeview it is displayed as expanded.

...and there are about 26 total AJAX requests that load the tree (all with "Expanded":false).  Is there anything here that would indicate why we are expanding each node and therefore loading all children?

One odd thing to note is that the plus/minus of all nodes including the root are in the "+" state even though all nodes are expanded.  When I click the plus/minus to collapse a node, it remains "+" and when I click it again to expand it, it changes to "-".  Not sure that sheds any light on the issue, but thought it was odd and perhaps useful.

Thanks,
--Ed

3 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 31 Oct 2013, 02:46 PM
Hello Ed,

The problem is caused by the line expanded: 'Expanded'. The DataSource (and HierarchicalDataSource) do not support data projection, thus this line does not do what you expect; it defines the expanded property with the value "Expanded", which is always evaluated to be true.

In order to resolve this, you can either serialize the data from the server with the lowercase expanded field, or post-process the data to project it.

Regards,
Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ed
Top achievements
Rank 1
answered on 31 Oct 2013, 05:53 PM
Hi Alex,

Works great.

I find the JSBin examples extremely useful.  Is there any way for me to see the list of all JSBin examples so I can browse through and satisfy my curiosity/resolve my own issues/learn a few new tricks?  I think this would be a fantastic extension to the current documentation.

Thanks,
--Ed
0
Alex Gyoshev
Telerik team
answered on 01 Nov 2013, 07:34 AM
Hello Ed,

I'm afraid there isn't such a list. However, we usually add scenarios that pop up often on the support channels to the online documentation -- I'll add this code right away. Furthermore, all samples from the docs are self-contained, and we work on some updates to the documentation site that will let you see the end results.

Regards,
Alex Gyoshev
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
Ed
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Ed
Top achievements
Rank 1
Share this question
or