How to populate dropdowntree with loadondemand

1 Answer 12 Views
DropDownList
Jerry
Top achievements
Rank 1
Iron
Iron
Iron
Jerry asked on 28 Jul 2025, 08:39 PM

I am using Vuejs 2.x.

I am trying to use the dropdowntree to display a large hierarchy.

I am also trying to use the ValueMapper to pre load the checked items.

The problem I have is that the valueMapper is not being called until I start clicking on nodes.

How to I get the valueMapper to check the correct nodes when the page is rendered?

Here is my code:


<body>
    <input id="dropdowntree">
<script>
  $(document).ready(function () {

    var localData = [
        { id: 1, text: "Parent 1", items: [
            { id: 2, text: "Child 1.1" },
            { id: 3, text: "Child 1.2" }
        ]},
        { id: 4, text: "Parent 2", items: [
            { id: 5, text: "Child 2.1" },
            { id: 6, text: "Child 2.2" }
        ]}
    ];
    
    
    var dropDownTree = $("#dropdowntree").kendoDropDownTree({
      placeholder: "Select an item...",
      dataSource: {  
        data: localData,
      schema: {
        model: {
            id: "id", 
            children: "items",
            fields: {
                id: { type: "number" },
                text: { type: "string" }
            }
        }
      }      
      },
      loadOnDemand: {
//THIS IS NOT CALLED UNTIL I START CLICKING NODES
        valueMapper: function (options) {
        var value = options.value;
        var item = localData.find(function (dataItem) {
            return dataItem.id == value;
        });
        options.success(item ? [item.id] : []);
        }
      },
      dataTextField: "text",
      dataValueField: "id",		
      //value: [2,5],    //SETTING THIS DID NOT HELP
      checkboxes: true, 
      checkAll: true,   
      autoClose: false
    });

    dropDownTree.value = [5]; // Trying to manually set value and call the valuemapper
  });
</script>
    
</body>

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 31 Jul 2025, 01:15 PM

Hello, Jerry,

In your current setup with Kendo UI DropDownTree in a jQuery context (even though you mentioned Vue.js 2.x), the valueMapper is only called when the widget needs to map primitive values (IDs) to data items — but only when it doesn’t already have those items loaded.

That means that:

  • If you’re setting .value([5]) after the widget is initialised and the data source already contains item 5, valueMapper won't be triggered.
  • If the data is not loaded, and the DropDownTree needs to resolve the value(s), then it will use valueMapper.

In case you have further Kendo UI for jQuery related questions I will suggest that you submit a thread in the Kendo UI for jQuery forum where my colleagues from the team and the clients using this product will be able to assist you further.

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
DropDownList
Asked by
Jerry
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Vessy
Telerik team
Share this question
or