Cannot fetch children nodes

4 posts, 0 answers
  1. Martin
    Martin avatar
    3 posts
    Member since:
    Feb 2014

    Posted 18 Mar 2014 Link to this post

    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!

  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 20 Mar 2014 Link to this post

    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.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Martin
    Martin avatar
    3 posts
    Member since:
    Feb 2014

    Posted 20 Mar 2014 in reply to Daniel Link to this post

    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





  5. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 24 Mar 2014 Link to this post

    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.

     
Back to Top
UI for ASP.NET MVC is VS 2017 Ready