Nilesh Rathod
Nilesh Rathod

Reputation: 149

Kendo UI Tree View Add text box and combo box inside tree view

We have a kendo tree-view already implemented in our web application. In our new requirement we have to add some additional controls inside tree view.

I am looking for an inbuilt functionality in kendo-ui where I can add textbox or combo-box inside the tree-view control. I go through a lot of threads available on kendo site but not get any similar implementation.

Please refer below screenshot to understand exact requirement.

enter image description here.

Upvotes: 0

Views: 1919

Answers (2)

Shai
Shai

Reputation: 3872

You can use the template configuration of the Kendo Options object like DontVoteMeDown suggested. Here's a solution that better fits your requirements: Add another data entry to the tree nodes that require it:

{
   text: "Item 1.1",
    value: 2,
    checked: false,
    extraOptions: ["", "Electrical Engineer", "Software Engineer"] // <-- Like this
}

Then in the template you use it like this:

<script id="item-template" type="text/x-kendo-template">
    # if (data.item.extraOptions) { #
        #= data.item.text #
        <select>
        # for (let index in data.item.extraOptions) { #
            # if (index == +index) { #
                <option>#= data.item.extraOptions[index] #</option>
            # } #
        # } #
        </select>
    # } else { #
        #= data.item.text #
    # } #
</script>

You can see a demo on Plunker.

Upvotes: 0

DontVoteMeDown
DontVoteMeDown

Reputation: 21465

There is not a built-in functionality for that, I think. It is a custom behaviour so you'll have to make it by yourself. You can achieve it using templates. Since you didn't added any code, I did a demo myself:

Widget configuration:

  $("#treeview").kendoTreeView({
    dataSource: {
      data: [{ 
        text: "Item 1",
        value: 1,
        showCombo: false,
        checked: false,
        items: [{
          text: "Item 1.1",
          value: 2,
          showCombo: true,
            checked: false
        },{
          text: "Item 1.2",
          value: 3,
          showCombo: true,
            checked: true
        }]
      }]
    },
    checkboxes: true,
    template: kendo.template($("#item-template").html())
  });

  $("#treeview")
    .on("change", "input.k-checkbox", function() {
        var $select = $(this).closest("div").find("select");

        if ($select.length > 0) {
        $select[($(this).is(":checked") ? "show" : "hide")]();
      }
    });

Template:

<script id="item-template" type="text/x-kendo-template">
# if (data.item.showCombo) { #
    #= data.item.text #
    <select # if (!data.item.checked) { # #="style='display:none'"# # } #>
    <option></option>
    <option>Mechanical Engineering</option>
    <option>Chemical Engineering</option>
    <option>Electrical Engineering</option>
  </select>
# } else { #
    #= data.item.text #
# } #
</script>

I hope it helps.

Demo

Upvotes: 3

Related Questions