3

I am new to angularjs, i want to use dropdownlist with treeview structure. i used both dropdownlist and treeview control separately but find difficulty in using together. can anyone have idea about how to use both together(dropdownlist+treeview)

2
  • i want this kind of control:- codeproject.com/KB/ThirdParty/862784/TelerikTV2.PNG Commented May 23, 2015 at 4:53
  • Treeview and Grouped Select are quite different things (treeview typically has expand/collapse and multiple levels). The image you linked to is simply a select with grouping. Commented May 23, 2015 at 7:53

1 Answer 1

2

You can use simple select control. I hope you are grouping values by some property. Lets say you have following data structure:

  $scope.data = [
      {
          id: 1,
          value: "Cat",
          type: "Animal"
      },
      {
          id: 2,
          value: "Dog",
          type: "Animal"
      },
      {
          id: 3,
          value: "Lion",
          type: "Animal"
      },
      {
          id: 4,
          value: "Parrot",
          type: "Bird"
      },
      {
          id: 5,
          value: "Sparrow",
          type: "Bird"
      },
  ];

You can group your data by "type" field and show a treeview dropdown as follows:

  <select ng-options="obj.value group by obj.type for obj in data track by $index"></select>

For more details you can look at https://docs.angularjs.org/api/ng/directive/ngOptions

Sign up to request clarification or add additional context in comments.

3 Comments

Yashika i have one more dout... using your solution it will display like tree structure but it wont allow me to click main parent i.e (type)... basically my requirement is like if i select main parent then all its children also selected. e.g. in this case if i select Animal automatically all children of animal should be selected
I think for this, you have to manually add one record for parent category and write code to select all if Parent is selected. For example, in $scope.data, put first record as {id:0, value: "Animal", type: "Animal"} and keep a watch on what is selected. If selected is "Animal", select all - add all animal type objects in selectedData array
how to make a three level structure??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.