How to set value with ID

3 posts, 0 answers
  1. Jonatan
    Jonatan avatar
    19 posts
    Member since:
    Feb 2014

    Posted 11 Oct 2018 Link to this post

    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. Jonatan
    Jonatan avatar
    19 posts
    Member since:
    Feb 2014

    Posted 11 Oct 2018 Link to this post

    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));
  3. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    1041 posts

    Posted 15 Oct 2018 Link to this post

    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.
Back to Top