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

How to set value with ID

2 Answers 800 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Jonatan
Top achievements
Rank 1
Jonatan asked on 11 Oct 2018, 09:20 AM

I am a little surprized to see that the dropdowntree selects values with string values rather than with id's. 

 

What if you have the same string value more than once in the tree?

 

How can I set the value of the dropdowntree with an id?

2 Answers, 1 is accepted

Sort by
0
Jonatan
Top achievements
Rank 1
answered on 11 Oct 2018, 09:38 AM

I think I found a work aorund to the wonky string selection

This seems to do the trick.

var id = 5;
$("#dropDownTree").data('kendoDropDownTree').value($("#dropDownTree").data('kendoDropDownTree').dataSource.get(id));
0
Veselin Tsvetanov
Telerik team
answered on 15 Oct 2018, 06:56 AM
Hi Jonatan,

Passing the DataItem retrieved from the DataSource object to the value() method of the DropDownTree is the proper approach in the discussed scenario. Alternatively, in order to use the ID of the item, you will have to set the ValuePrimitive() option of the widget to true and explicitly set a DataValueField():
@(Html.Kendo().DropDownTree()
                .Name("dropdowntree")
                .DataTextField("Name")
                .DataValueField("EmployeeId")
                .ValuePrimitive(true)
                .DataSource(dataSource => dataSource
                    .Read(read => read
                        .Action("Remote_Data_Binding_Get_Employees", "DropDownTree")
                    )
                )
    )

Regards,
Veselin Tsvetanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
DropDownTree
Asked by
Jonatan
Top achievements
Rank 1
Answers by
Jonatan
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Share this question
or