Load a TreeView from a DropDownList onChange event

4 posts, 0 answers
  1. Davi Rodrigues
    Davi Rodrigues avatar
    4 posts
    Member since:
    Sep 2009

    Posted 24 May 2013 Link to this post

    Morning folks!

    What I'm trying to do is...when I change the item of the dropdownlist, I'll need to REload the TreeView with the selectedValue of the dropDownList.

    In my case, as I'm a new kendoui user, I'm not going on the right track, for sure.

    Any ideas?

    Here's my JS dumb script...hope you can help me!

    <script type="text/javascript">
     
        function onChange(e) {
            $.ajax({
                url: "/Nav/MontaMenu/",
                dataType: "json",
                cache: false,
                type: 'GET',
                data: { nomePastaSelecionada: this.text(), caminhoPastaSelecionada: this.value() },
                success: function (result) {
     
                    $('#treeview').kendoTreeView();
     
                    var tvProjeto = $('#treeview').getKendoTreeView();
     
                    tvProjeto.destroy();
                     
                    var dataSource = new kendo.data.DataSource({
                        data: result
                    });
                     
                    dataSource.fetch(function () {
                        tvProjeto.setDataSource({
                            data: dataSource
                        });                   
                    });
                }
            });
        }
    </script>

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 27 May 2013 Link to this post

    Hello Davi,


    In the current implementation the data is passed correctly to the AJAX request. In the success event if the TreeView was already initialized, you don't need to destroy it and create it again. You could just set the new data for it's dataSource.
    E.g.
    success: function (result) {
        var tvProjeto = $('#treeview').data("kendoTreeView");
        tvProjeto.dataSource.data(result);
    }

    Please let me know if this approach is working in the current scenario or I could assist you further.

     

    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. Davi Rodrigues
    Davi Rodrigues avatar
    4 posts
    Member since:
    Sep 2009

    Posted 27 May 2013 Link to this post

    Good morning Dimiter, 

    Well...it seemed to work fine for just one node level...why it doesn't load the inner nodes?!

    Regards,
    Davi Rodrigues
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 27 May 2013 Link to this post

    Hello Davi,


    I am not aware of the current TreeView implementation and the format of the returned data. Please make sure the format of the result  variable is correct and the TreeView is initialized with the loadOnDemand option set to false. This means that all nodes will be fetched initially. Here is a small JS Bin example, which demonstrates this. 


    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!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready