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

Cannot fetch children nodes

3 Answers 114 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 18 Mar 2014, 11:06 AM
Hi,

I am trying fetch children nodes for destination node in drop event. Everything works ok, when read transport is configured as an object. But when I configure it as a function, it just reads root level nodes instead of children (there is no parameter id in data).

My code looks like this:

01.drop: function(e) {
02.    var _tree = this,
03.        _src = _tree.dataItem(e.sourceNode),
04.        _dest = _tree.dataItem(e.destinationNode),
05.        _pos = e.dropPosition;
06.             
07.        if (_pos == "over") {
08.            if (_dest.hasChildren) {
09.                if (!_dest.loaded()) {
10.                    var _result = _dest.children.fetch();
11.                            
12.                }
13.            }
14.        }
15.}

And transport read function:

01.transport: {
02.    read: function(options) {
03.        $.ajax({
04.            url: '@Url.Action("Read", "TreeView")',
05.            type: 'GET',
06.            dataType: 'json',
07.            data: options.data
08.        }).success(function (result) {
09.            return options.success(result);
10.        }).error(function (result) {
11.            return options.error(result);
12.        });
13.    }
14.}


Thanks in advance!

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 20 Mar 2014, 11:56 AM
Hello Martin,

You should use the node load method in order for the ID to be passed with the data:
_dest.load();

Also,  are you using the treeview drop event? The treeview should automatically load the children when a node is dropped on another one which has children and they have not been loaded yet. 

Regards,
Daniel
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Martin
Top achievements
Rank 1
answered on 20 Mar 2014, 12:14 PM
Hello Daniel,

thanks for reply. I can't use .load() because it has no callback like .fetch(). I need to do some work on loaded items, so after .fetch() I can do this:

_result.then(function response(result) {
    // do some work on loaded data
});

Can I do the same with .load() somehow?

And yes, I am using drop event and I want modify dropped item (when it is dropped over collapsed and not loaded node) according to target node child items. That's why I had to use .fetch() method because .load() does not provide callback to newly loaded data.

Regards
Martin





0
Daniel
Telerik team
answered on 24 Mar 2014, 08:17 AM
Hello again Martin,

I am afraid that this is not supported by the load method. You will need to bind a handler to the children dataSource requestEnd event or to the treeview dataBound event in order to execute some logic after the children has been loaded.

Regards,
Daniel
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
TreeView
Asked by
Martin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Martin
Top achievements
Rank 1
Share this question
or