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

Force web service refresh of data

7 Answers 226 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Pierre Chew
Top achievements
Rank 1
Pierre Chew asked on 14 May 2009, 06:03 PM
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

7 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 15 May 2009, 10:58 AM
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.
0
Kristof
Top achievements
Rank 1
answered on 01 Jul 2009, 11:52 AM
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
0
Atanas Korchev
Telerik team
answered on 01 Jul 2009, 12:25 PM
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.
0
Kristof
Top achievements
Rank 1
answered on 01 Jul 2009, 12:36 PM
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
0
Atanas Korchev
Telerik team
answered on 01 Jul 2009, 12:38 PM
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.
0
Kristof
Top achievements
Rank 1
answered on 01 Jul 2009, 12:45 PM
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
0
Atanas Korchev
Telerik team
answered on 01 Jul 2009, 01:32 PM
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.
Tags
TreeView
Asked by
Pierre Chew
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Kristof
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or