Force web service refresh of data

8 posts, 0 answers
  1. Pierre Chew
    Pierre Chew avatar
    22 posts
    Member since:
    Aug 2012

    Posted 14 May 2009 Link to this post

    I would like to know if it is possible to force a a webservice call when expanding a node that has already been expanded.  The reason I want to do this is that the description of certain nodes within our tree contain "counters" and these counters can change on the server from time to time. 

    In our previous versino of the tree we allowed users to click on a context menu item calld "refresh" that automatically made a call to the server and refreshed the nodes that were children of this node. Is there an easy way to do this by resetting a flag on the node to indicate that it has not already been populated by the webservice?

    Thanks,

    Pierre Chew
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 15 May 2009 Link to this post

    Hi Pierre Chew,

    I have already replied to your support ticket:

    Yes, this is possible. Here are the steps you need to take:

    1. Collapse the node:
    node.collapse();

    2. Clear its nodes and set its ExpandMode back to WebService:
    node.get_treeView().trackChanges();
    node.get_nodes().clear();
    node.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.WebService);
    node.get_treeView().commitChanges();

    Now if you expand the node - it will reload its nodes from the web service.

    I hope this helps.



    Greetings,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Kristof
    Kristof avatar
    12 posts
    Member since:
    Apr 2009

    Posted 01 Jul 2009 Link to this post

    Hi,

    I want to do the same as Pierre Chew, refresh a tree which get's its data from a webservice.

    The method you propose does work, but the problem is that the display is also updated when the nodes are removed... Is there a way to update the nodes without the user seeing the whole node collapse and expand again?

    When using an asp.net updatepanel and expandmode serverside, the update works seamlessly without any flickering. I would like the same visual effect, but with the better performance of webservices... (the updatepanel approach causes 2MB updates which is unacceptable).

    E.g. update the nodes in the background, and then replace all children at once?

    Kind Regards,
    Kristof
  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 01 Jul 2009 Link to this post

    Hello Kristof,

    This can be currently achieved only by using the internal API. Still here is a working solution:

            <asp:ScriptManager runat="server" ID="ScriptManager1">
            </asp:ScriptManager>

            <script type="text/javascript">
                function refresh() {
                    var treeView = $find("RadTreeView1");

                    var node = treeView.get_nodes().getNode(0);
                    node.set_expandMode(Telerik.Web.UI.TreeNodeExpandMode.WebService);
                    treeView._loadChildrenFromWebService(node);
                    return false;
                }

                var _onNodeLoadingSuccess = Telerik.Web.UI.RadTreeView.prototype._onNodeLoadingSuccess;
                Telerik.Web.UI.RadTreeView.prototype._onNodeLoadingSuccess = function(sender, eventArgs)
                {
                    var node = eventArgs.get_context();
                    node.get_nodes().clear();
                   
                    _onNodeLoadingSuccess.apply(this, arguments);
                }
            </script>
            <asp:Button runat="server" ID="Button1" OnClientClick="return refresh()" />
            <telerik:RadTreeView runat="server" ID="RadTreeView1">
                <WebServiceSettings Path="Default.aspx" Method="GetNodes"></WebServiceSettings>
                <Nodes>
                    <telerik:RadTreeNode Text="Node1" ExpandMode="WebService" />
                </Nodes>
            </telerik:RadTreeView>

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Kristof
    Kristof avatar
    12 posts
    Member since:
    Apr 2009

    Posted 01 Jul 2009 Link to this post

    Cool! Thanx for your fast reply. This works very well.

    I have one more question. I would like the tree to refresh every x seconds, where in the code can I restart the timeout for another x seconds? E.g. can I get some notification when the reload has completed...

    In my test now I restarted the timer like this (code in bold):

    Telerik.Web.UI.RadTreeView.prototype._onNodeLoadingSuccess = function(sender, eventArgs) 
    {
            var node = eventArgs.get_context();
            node.get_nodes().clear();
                    
            _onNodeLoadingSuccess.apply(this, arguments);

              setTimeout('updateTree()', 10000);

    }

    But then the timer somethimes already fires after 5 seconds instead of 10, so that does not seem to be the correct place...

    Thanks in advance,
    Kristof
  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 01 Jul 2009 Link to this post

    Hi Kristof,

    You can try using setInterval instead of setTimeout. In that case you should call it once when the page loads.

    <script type="text/javascript">
    function pageLoad()
    {
           window.setInterval("updateTree()", 10000);
    }
    </script>
    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Kristof
    Kristof avatar
    12 posts
    Member since:
    Apr 2009

    Posted 01 Jul 2009 Link to this post

    Ok, but the problem with this approach is that when the refresh takes longer then the timeout, a new refresh will already start when the previous is still busy (it's quite alot of data we are working with here).

    To avoid that, I want to start the next timeout as soon as the previous refresh is completely finished. But then I need to find out some way when the refresh is completely finished...

    Kind Regards,
    Kristof
  8. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 01 Jul 2009 Link to this post

    Hello Kristof,

    After calling _onNodeLoadingSuccess.apply() the node will be populated..

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top