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

HierarchicalDataSource with local and remote data

3 Answers 221 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
BigzampanoXXl
Top achievements
Rank 1
BigzampanoXXl asked on 27 Mar 2014, 03:32 PM
Hello,

I have a problem with the HierarchicalDataSource in my treeview. I have a 3+ level datasource. The first and the second level are coming from local data, the third and every following level is coming by a webservice-method.

So far so good: First and second level get displayed perfectly, but with the third one I have some problems. Its loading data, but then it removes the icon (which says that Subfolders exist) and no subfolders are shown.

Fact 1: It jumps into the webservice-method, it returns data (all the subfolders), it gets into the success of the ajax-call

Fact 2: If I remove the second level and make the third+ level as my second one, everything works fine!!! (But I dont want to load the second level again, when I already have it in my folderStructure-object)

Here is my code:

var dataSource = new kendo.data.HierarchicalDataSource({
    data: folderStructure,
    schema: {
        model: {
            id: "Id",
            hasChildren: "HasChilds",
            children:
            {
                schema: {
                    data: "items",
                    model: {
                        id: "Id",
                        hasChildren: "HasChilds",
                        children: {
                            transport: {
                                read: function (options)
                                {
                                    var id = options.data.Id;
                                    $.ajax({
                                        type: "POST",
                                        url: webserviceUrl + "/GetSubFolders",
                                        data: JSON.stringify({ parentFolderId: id }),
                                        processData: false,
                                        contentType: "application/json; charset=utf-8",
                                        dataType: "json",
                                        xhrFields: {
                                            withCredentials: true
                                        },
                                        success: function (data)
                                        {
                                            options.success(JSON.parse(data.d));
                                        },
                                        error: function (data)
                                        {
                                            options.error(data);
                                        }
                                    });
                                }
                            },
                            schema: {
                                model: {
                                    id: "Id",
                                    hasChildren: "HasChilds"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
});


I hope someone can help me,

Thank you,
Best regards.

3 Answers, 1 is accepted

Sort by
0
BigzampanoXXl
Top achievements
Rank 1
answered on 28 Mar 2014, 12:51 PM
Hello,

I found the problem. In level 2 I say --> data: "items" --> because it should take the subfolders by the items-property of my folderStructure. Based on that, also the third level trys to get the data by an items-property. From my remote endpoint i get the data as an array. If I put this array in a new array on the property "items" everything works fine.

Here what I had to do in the success of my Webservice-call:
var set = new Array();
set.items = JSON.parse(data.d);
options.success(set);


I tried to reset somehow the "data"-property in the third level of my hierarchicaldatasource (setting it to undefined, null, "", whatever...) doesn't work. 

Now my question is: bug or feature? I see it as a bug if I can only define once the property on which the subfolders are set. 
It's working now, but actually not the most beautiful solution.

Best regards.
0
Accepted
Atanas Korchev
Telerik team
answered on 31 Mar 2014, 03:43 PM
Hello Dietmar,

Indeed you need to reset the schema.data option as it is inherited by the children levels. I created a sample demo which shows the same: http://trykendoui.telerik.com/@korchev/ikUN

Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
BigzampanoXXl
Top achievements
Rank 1
answered on 02 Apr 2014, 09:15 AM
Hey Atanas,

thank you, that was the solution. Would be nice to have this in the documentation.

Best regards
Tags
TreeView
Asked by
BigzampanoXXl
Top achievements
Rank 1
Answers by
BigzampanoXXl
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or