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

Load a TreeView from a DropDownList onChange event

3 Answers 223 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Davi Rodrigues
Top achievements
Rank 1
Davi Rodrigues asked on 24 May 2013, 12:05 PM
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>

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 27 May 2013, 08:28 AM
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!
0
Davi Rodrigues
Top achievements
Rank 1
answered on 27 May 2013, 10:46 AM
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
0
Dimiter Madjarov
Telerik team
answered on 27 May 2013, 11:12 AM
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!
Tags
DropDownList
Asked by
Davi Rodrigues
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Davi Rodrigues
Top achievements
Rank 1
Share this question
or