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

Binding TreeView to a JSON-Result

4 Answers 613 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mathias
Top achievements
Rank 1
Mathias asked on 26 Jul 2012, 04:14 PM

Hello,

we are changing our application from Telerik Controls to Kendo UI. But changing the TreeView is a little bit difficult. I hope you can help me:

With Telerik we used the OnDataBinding- Event, called a controller-class and bound a json-result to our tree: tree.bindTo(jsonObject)
Well this isn't possible with KendoUI.

So I tried the DataSource-thing on our tree:

@(Html.Kendo().TreeView()
.Name("TreeView")
.DataTextField("Text")
.DataImageUrlField("ImageUrl")
.DataUrlField("Url")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("GetTreeData", "Home")
)
)
.ExpandAll(true)

Without all these DataTextField, DataImage.. stuff nothing worked so after hours I found out that I need them (there has to be a better documentation... please). But: How can I add ChildElements? With hasChildren (as a Property on the Json-Object) Ithe TreeView knows that there are children but I also wanna show them after binding (.ExpandAll(true).... <-- wanna use it!)

I really hope you can help me. I want to bind the complete tree-structure at once. No Load on demand. Is there any solution for doing that?

And if I have my complete tree... how am I able to rebind it? We need to refresh the tree very often, so I hope you can show me a possibility to do that.

Thank you very much!
Mathias

4 Answers, 1 is accepted

Sort by
0
Mathias
Top achievements
Rank 1
answered on 06 Aug 2012, 09:32 AM
So as I can see there is no solution fot this problem :/ Hopefully in the next release it will be possible to bind the complete tree at once and not just the first level. Using the Telerik Extensions it was possible. And we really need it!
0
muralidhar
Top achievements
Rank 1
answered on 25 Sep 2012, 08:47 AM
Do we have any function like "bindTo" in kendo UI, In latest version i could not find it.
0
Hari
Top achievements
Rank 1
answered on 10 Dec 2012, 05:06 PM
Hi,

We are trying to do the same thing. Is it really not possible to load the complete Tree structure atonce? Here is what I am trying to do.

I am trying to convert my sample XML file as JSON object and set that as a datasource to my tree view control. Its not working.
I am sure that I am missing something here but not sure what's that. Please help me.

Here is my code in Controller class where I am loading the XML file and retruning as JSON


        public JsonResult Employees()
       
{

           
XElement xdoc = XElement.Load("C:\\Users\\a409114\\Desktop\\TreeView.xml");
           
return Json(xdoc, JsonRequestBehavior.AllowGet);
       
}

Here is my code in the view file where I am invoking the action name "Employees" in my controller class "TreeViewController".


<div class="demo-section">
@(Html.Kendo().TreeView()
   
.Name("treeview")
    
.DataTextField("vehicles")
   
.DataSource(dataSource => dataSource
       
.Read(read => read
           
.Action("Employees", "TreeView")
       
)
   
)
)
</div>

<style scoped>
.demo-section {
    width
: 200px;
}
</style>

Here is my sameple XML file:


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tree>
<vehicles>
   
<car>FM-1100</car>
   
<car>FM-4200</car>
   
<bike>FM-3100</bike>
</vehicles>
<personnel>
   
<client>GH-3000</client>
   
<vip>GH-3100</vip>
</personnel>
</tree>

This is not loding the Tree View Control!

Can you please help me?
0
Josh
Top achievements
Rank 1
answered on 13 Dec 2012, 10:14 PM
Have you tried using the "RequestEnd" event of the .Read and then call a function to expand the items?

<div class="demo-section">
    @(Html.Kendo().TreeView()
 
    .Name("treeview")
 
    .DataTextField("vehicles")
 
    .DataSource(dataSource => dataSource
 
        .Read(read => read
             
.Action("Employees", "TreeView")
         
).Events(e => e
            .RequestEnd("Expand")
    
)
)
</div>


<script>
function Expand() {
    var treeview = $("#Treeview").data("kendoTreeView");
    treeview.expand(".k-item");
}

</script>

Tags
TreeView
Asked by
Mathias
Top achievements
Rank 1
Answers by
Mathias
Top achievements
Rank 1
muralidhar
Top achievements
Rank 1
Hari
Top achievements
Rank 1
Josh
Top achievements
Rank 1
Share this question
or