Turn off lazy loading?

3 posts, 1 answers
  1. Randy Hompesch
    Randy Hompesch avatar
    45 posts
    Member since:
    Nov 2008

    Posted 31 Jul 2013 Link to this post

    Hi,
    I seem to be having an issue with client side events and lazy loading.
    I have a tv on my layout view as follows:

    @Html.Kendo().TreeView().Name("MainMenu").DataSource(dataSource => dataSource
    .Read(read => read.Action("Index", "MainMenu"))).DataTextField("MenuText").DataUrlField("Url")

    I have code on the server that correctly returns the parts of the tv as necessary.
    All is well. My tree displays. When I click on  a parent node a server call is made and the children are show.
    Great.

    Now the trouble.
    I add the following javascript  and when I click on a node I get the alert just fine. However, once, I click ok, I get an error in kendo.all.min.js. Attached is a screenshot of the error.

    Thanks ... Ed


    function _LayoutOnLoad()
    {
        $(function ()
        {
            $("#MainMenu").kendoTreeView({
                select: OnMainMenuSelect
            })
        });
    }
    function OnMainMenuSelect(e)
    {
        alert("Selecting: " + e.node.textContent);
    }
  2. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2156 posts

    Posted 01 Aug 2013 Link to this post

    Hi Randy,


    When the following code snippet is executed
    $("#MainMenu").kendoTreeView({
        select: OnMainMenuSelect
    })

     the TreeView is initialized for a second time and the previous configurations are lost. As a solution, you could either bind to the event in the TreeView configuration.
    E.g.
    .Events(e => e.Select("OnMainMenuSelect"))
    OR
    get the data for the TreeView and use the bind method to bind to the event on run-time.
    E.g.
    var tree = $("#MainMenu").data("kendoTreeView");
    tree.bind("select", function(e){
        //custom logic
    });

    I hope that this information was helpful for you. I wish you a great day!

     

    Regards,
    Dimiter Madjarov
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Randy Hompesch
    Randy Hompesch avatar
    45 posts
    Member since:
    Nov 2008

    Posted 01 Aug 2013 Link to this post

    Fantastic! That one really had me stuck.
    Thank you very much!
    Ed
Back to Top