Can you fill a LoadOnDemand item from WebService with script?

2 posts, 0 answers
  1. Andrew
    Andrew avatar
    39 posts
    Member since:
    Feb 2011

    Posted 04 Nov 2011 Link to this post

    I'm trying to set up a 'lazy spool', background-cache type system in a very large menu which loads its items from a webservice.
    when a menu item opens (and populates its items from a webservice), I'd like to catch the Populated event for that item, and iterate the loaded items and force a populate on them in the background.

    I thought calling get_items() would initiate the webservice call - but it doesn't seem to. Open is the only thing which seems to start the webservice request.

    Is this technically possible?

    function TelerikMenu_OnClientItemPopulated(sender, eventArgs) {
            var items = eventArgs.get_item().get_items();
            for (var i = 0; i < items.get_count(); i++) {
                var item = items.getItem(i);
                if (item != null) {
                    item.get_items();
                }
            }
     
    }
  2. Andrew
    Andrew avatar
    39 posts
    Member since:
    Feb 2011

    Posted 07 Nov 2011 Link to this post

    OK, I have made some progress on this, finding the undocumented function _loadChildrenFromWebService in the forums.

    function TelerikMenu_ItemOpened(sender, eventArgs) {
        var _i = eventArgs.get_item();
        var items = _i.get_items();
            for (var i = 0; i < items.get_count(); i++) {
                var item = items.getItem(i);
                if (item != null) {
                    if (item.get_expandMode() == 1 && item.get_items().get_count() == 0) {
                        item.get_menu()._loadChildrenFromWebService(item);
                    }
                }
            }
    }


    The problem was that if you have a loading template - then the _loadChildrenFromWebService call actually shows the menu expanding... Remove that, and it all works as expected. Now - when a menu item is opened, any un-cached children are preloaded in the background. Now my menu, even though it is webservice populated, is visibly as quick as a menu with preloaded items. Nice one !! :)
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top