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

Load/Reload TreeView node

15 Answers 1307 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 06 Aug 2013, 05:58 PM
Hi;

I've read many different threads on the ability to handle the TreeView content. I am running into an issue that I cannont get working smoothly or not at all. I have a TreeView. This TreeView requires updating when I make an update to a DB. The loading of the TreeView works based on queries on the DB. My main problem is that after I make the DB update I need to request a reload of the current node. Updates are based on the selected TreeView node. I am performing operations like selectedDataItem.load(); but I cannot get the loading to work. It works if the current node has not been expanded. It will not work f the current node has already been expanded. It also does not work if the node had been expanded and no child nodes are present. I.E. after this point adding to the node also does nothing to the TreeView. I do know that the data items used for populating the TreeView are correct because if I restart my app and open the TreeView the items are loaded. What I would like to know is what is the correct way to dynamcially update the TreeView regardless of the TreeView state.

Peter

15 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 08 Aug 2013, 12:05 PM
Hello Peter,

If the node has already been expanded then it will be marked as loaded and a request will not be made. You should use the loaded method before the load method in order to reload the node.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Peter
Top achievements
Rank 1
answered on 08 Aug 2013, 05:14 PM
Hi;
This is my treeview defintion:

@(Html.Kendo().TreeView()
   .Name("GroupTreeView")
   .DataTextField("Name")
   .HtmlAttributes(new { @class = "layout" })
   .DataSource(
      dataSource => dataSource
         .Read(read => read.Action("GetManagmentLevel", "SystemManagement"))
               )
      .Events
      (
         events =>
         {
            events.Select("OnGroupSelect");
            events.Expand("OnGroupExpand");
            events.DataBound("OnGroupTreeBound");          
         }
      )                                                                                  
)

I am performing the following on the TreeView control:

var treeView = $('#GroupTreeView').data('kendoTreeView');
if (treeView != null && CurrentlyActiveGroupTreeNode != null)
{       
    var selectedDataItem = treeView.dataItem(CurrentlyActiveGroupTreeNode);                      
    selectedDataItem.haschildren = true;
    treeView.collapse(CurrentlyActiveGroupTreeNode);
    selectedDataItem.loaded(false);
    selectedDataItem.load();
    treeView.expand(CurrentlyActiveGroupTreeNode);
}

I've validated that the Action that is being requested by the tree is working, is being called. But the tree does expand properly in IE - but looks to be working in Chrome.

Peter
0
Daniel
Telerik team
answered on 12 Aug 2013, 02:56 PM
Hello again Peter,

The node will not be expanded since the collapse animation will not be completed when the method is used. Please check if not calling the collapse method resolves the problem. Also, you should call the expand method in the dataBound event in order to avoid duplicate requests e.g.

var treeView = $('#GroupTreeView').data('kendoTreeView');
if (treeView != null && CurrentlyActiveGroupTreeNode != null)
{       
    var selectedDataItem = treeView.dataItem(CurrentlyActiveGroupTreeNode);                      
    selectedDataItem.haschildren = true;  
    selectedDataItem.loaded(false);
    selectedDataItem.load();
    treeView.one("dataBound", function () {
        treeView.expand(CurrentlyActiveGroupTreeNode);
    });
}
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Peter
Top achievements
Rank 1
answered on 12 Aug 2013, 06:02 PM
Hi;

No; the code you prvoded had no effect. Dynamic expansion works with Google and with Firefox, but not with IE[10]

Peter
0
Daniel
Telerik team
answered on 15 Aug 2013, 06:33 AM
Hello Peter,

I created a small jsBin example that demonstrates this scenario. At least on my side a request is made and the node is expanded in all browsers. Please check it and let me know if I am missing something.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Accepted
Peter
Top achievements
Rank 1
answered on 16 Aug 2013, 11:08 AM
Hi;

Ok; this example was not taking into consideration that we are dynaically loading tree nodes at run tim, i.e. not the entiere tree). The problem did revolve around IE and we came to the conclusion that IEs aggressive caching strategy was causing problems. We have turned off caching in the particular area of concern and IE now behaves as wanted.


Peter
0
Steven
Top achievements
Rank 1
answered on 21 Dec 2013, 12:26 AM
You say you "turned off caching in the particular area of concern and IE now behaves as wanted" but you haven't told us HOW to did this. Please post some instructions (or code sample) to help the rest of us out.

Thanks!
0
Peter
Top achievements
Rank 1
answered on 23 Dec 2013, 11:43 AM
My comment was with regards to standard cache management capabilities [provided by Microsoft web technologies as well as other web management systems]. I didn't EXPLAIN HOW to do this as it is standard knowledge. I do not know what tools you are using so you should review caching strategies with the tools that you use. My answer dealt with the fact that refreshing was not working because of IE's aggressive caching strategy and was resolved by turning it off (in MS ASP.NET MVC tech - you can control caching of requests from the controller that is being called).

Peter
0
Steven
Top achievements
Rank 1
answered on 24 Dec 2013, 07:43 PM


When a node in the
Kendo TreeView is expanded the READ calls a function in my home controller to
get a simple list of nodes for the next level. That C# function is shown below.
I don’t see how I could also return a date time from this function to disable
caching. Please explain.

 

 

        public ActionResult
BindHierarchyTree([DataSourceRequest]DataSourceRequest request, BindHierarchyTreeReq bindHierarchyTreeReq)

        {

            // By default, get the children of the ROOT node

            var parentNode =
SessionHierarchyRootNode;

 

            // If an expanded node ID is provided, get the children of
the EXPANDED node

            if
(bindHierarchyTreeReq.ExpandedNodeID != null)

            {

                var expandedNodeGUID = Guid.Parse(bindHierarchyTreeReq.ExpandedNodeID);

               
parentNode = SessionHierarchyRootNode.FindNodes(x => x.GUID ==
expandedNodeGUID, true)[0];

            }

 

            // Build list of simple tree nodes

            var simpleTreeNodes = new List<VMSimpleTreeNode>();

 

            foreach (var childNode in parentNode.Children)

            {

                var hasChildren =
childNode.hasChildren;

               
simpleTreeNodes.Add(new VMSimpleTreeNode(childNode.GUID.ToString(), childNode.Title,
hasChildren));

            }

 

            // Return simple tree nodes

            return Json(simpleTreeNodes,
JsonRequestBehavior.AllowGet);

        }

 

0
Petur Subev
Telerik team
answered on 26 Dec 2013, 07:34 AM
Hello,

I assume you want to send a timestamp from the client to the server to avoid caching (same approach is used when jQuery's ajax cache:false option is used). How to send additional parameter with the dataSource is covered in the documentation here:

http://docs.kendoui.com/api/framework/datasource#configuration-transport.read.data

e.g.

var dataSource = new kendo.data.DataSource({
  transport: {
    read: {
      dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
      data: function() {
        return {
          _: new Date().getTime()
        };
      }
    }
  }
});


Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Peter
Top achievements
Rank 1
answered on 26 Dec 2013, 02:13 PM
Hi;

The response that Petur gave is another [common] technique to make sure a request submitted will generate a new response (and not a cached one). If you are using ASP.NET MVC then on the controller you can set an attribute on the class definition - [Core.NoCache] which turns off caching for requests made to the controller.

Peter
0
Steven
Top achievements
Rank 1
answered on 02 Jan 2014, 06:51 PM
TreeView Expand Node Caching Issue in IE --- THIS SOLUTION WORKED FOR ME...

You can disable caching for ALL action methods in your controller using this attribute:

[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public class MyController : Controller
{
}

Read more here:
http://stackoverflow.com/questions/1160105/disable-browser-cache-for-entire-asp-net-website


0
Paul
Top achievements
Rank 1
answered on 20 Feb 2014, 10:38 AM
Hi I have the same problem as the original post, i have tried the recommended solution and it gives an error when the selectedDataItem.load() method is called, the error is "Uncaught TypeError: Cannot read property 'length' of undefined "

my code is as follows:

    function RefreshSelectedNode() {

        var treeview = $("#treeview").data("kendoTreeView");
        var getitem = treeview.dataSource.get(selectedId);
        var selectitem = treeview.findByUid(getitem.uid);

        if (treeview != null && selectitem != null) {
            var selectedDataItem = treeview.dataItem(selectitem);
            selectedDataItem.haschildren = true;
            treeview.collapse(selectitem);
            selectedDataItem.loaded(false);
            selectedDataItem.load();
            treeview.one("dataBound", function () {
                treeview.expand(selectitem);
            });
        }
    }


what am i doing wrong?







0
Petur Subev
Telerik team
answered on 24 Feb 2014, 12:20 PM
Hello Paul,

Demonstrate your case with a JsBin example so we can further investigate what exactly causes the exception.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Paul
Top achievements
Rank 1
answered on 06 Mar 2014, 02:29 PM
Hi Petur 

I was able to resolve this by only calling the RefreshSelectedNode() after the page that was submitted had finished loading by adding this to my Create View
$(document).ready(function () {

                if(reloadtree)
                    RefreshSelectedNode();
}); 

I dont know why as the treeview is loaded on a different "thread" so to speak, but it works....
Tags
TreeView
Asked by
Peter
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Peter
Top achievements
Rank 1
Steven
Top achievements
Rank 1
Petur Subev
Telerik team
Paul
Top achievements
Rank 1
Share this question
or