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)
-
i want this kind of control:- codeproject.com/KB/ThirdParty/862784/TelerikTV2.PNGAzad Shaikh– Azad Shaikh2015-05-23 04:53:46 +00:00Commented 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.Phil Degenhardt– Phil Degenhardt2015-05-23 07:53:16 +00:00Commented May 23, 2015 at 7:53
Add a comment
|
1 Answer
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
3 Comments
Azad Shaikh
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
Yashika Garg
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
priya vyas
how to make a three level structure??