File tree Expand file tree Collapse file tree 6 files changed +48
-7
lines changed Expand file tree Collapse file tree 6 files changed +48
-7
lines changed Original file line number Diff line number Diff line change 9
9
ng-keydown ="$ctrl.searchKeydown($event) " />
10
10
</ div >
11
11
< ul >
12
- < dropdown-tree-option-row ng-repeat ="option in $ctrl.options track by $index "
12
+ < dropdown-tree-option-row ng-repeat ="option in $ctrl.options | orderBy:$ctrl.settings.displayProperty:false:$ctrl.customCompare track by $index "
13
13
option ="option "
14
14
settings ="$ctrl.settings "
15
15
option-clicked ="$ctrl.optionClicked(option) "
18
18
focus-previous ="$ctrl.focusPrevious() "
19
19
catch-keydown ="$ctrl.catchKeydown(event) "
20
20
reset-focus-counter ="$ctrl.resetFocusCounter(element) "
21
- search-text ="{{$ctrl.searchText}} ">
21
+ search-text ="{{$ctrl.searchText}} "
22
+ custom-compare ="$ctrl.customCompare ">
22
23
</ dropdown-tree-option-row >
23
24
</ ul >
24
25
</ div >
Original file line number Diff line number Diff line change 58
58
foldersOpen : true ,
59
59
openFolderWhenInnerSelected : false ,
60
60
closeOnSelectionLimitReached : false ,
61
+ sortByDisplayProperty : false ,
61
62
} ;
62
63
63
64
this . settings = angular . extend ( { } , this . defaultSettings ) ;
65
+
66
+ const vm = this ;
67
+ function customCompare ( a , b ) {
68
+ if ( ! vm . settings . sortByDisplayProperty ) {
69
+ return 0 ;
70
+ }
71
+ if ( a . value < b . value ) {
72
+ return - 1 ;
73
+ } else if ( a . value > b . value ) {
74
+ return 1 ;
75
+ }
76
+ return 0 ;
77
+ }
78
+ vm . customCompare = customCompare ;
64
79
}
65
80
66
81
$onChanges ( changes ) {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export default function optionRowComponent() {
14
14
catchKeydown : '&' ,
15
15
resetFocusCounter : '&' ,
16
16
searchText : '@' ,
17
+ customCompare : '<' ,
17
18
} ,
18
19
} ;
19
20
Original file line number Diff line number Diff line change 20
20
</ div >
21
21
< ul class ="children "
22
22
ng-if ="$ctrl.isFolder() && ($ctrl.isOpen || ($ctrl.shouldBeVisible() && $ctrl.searchText.length !== 0)) ">
23
- < dropdown-tree-option-row ng-repeat ="option in $ctrl.getChildOptions() track by $index "
23
+ < dropdown-tree-option-row ng-repeat ="option in $ctrl.getChildOptions() | orderBy:$ctrl.settings.displayProperty:false:$ctrl.customCompare track by $index "
24
24
option ="option "
25
25
settings ="$ctrl.settings "
26
26
option-clicked ="$ctrl.innerClicked(option) "
Original file line number Diff line number Diff line change 8
8
$onInit ( ) {
9
9
this . options = [
10
10
{
11
- name : 'testoption ' ,
11
+ name : 'b ' ,
12
12
label : 'testoption label' ,
13
13
} ,
14
14
{
15
- name : 'test folder ' ,
15
+ name : 'a ' ,
16
16
label : 'test folder label' ,
17
17
children : [
18
18
{
19
- name : 'test child option' ,
20
- label : 'test child option label' ,
19
+ name : 'c' ,
20
+ label : 'test child option c' ,
21
+ } ,
22
+ {
23
+ name : 'f' ,
24
+ label : 'test child option f' ,
25
+ } ,
26
+ {
27
+ name : 'd' ,
28
+ label : 'test child option d' ,
21
29
} ,
22
30
] ,
23
31
childoptions : [
Original file line number Diff line number Diff line change @@ -129,6 +129,14 @@ <h3>Example settings</h3>
129
129
closeOnSelectionLimitReached
130
130
</ label >
131
131
</ div >
132
+ < div >
133
+ < label >
134
+ < input type ="checkbox "
135
+ ng-model ="$ctrl.settings.sortByDisplayProperty "
136
+ ng-change ="$ctrl.changeSettings() " />
137
+ sortByDisplayProperty
138
+ </ label >
139
+ </ div >
132
140
</ div >
133
141
</ div >
134
142
</ div >
@@ -309,6 +317,14 @@ <h3>Settings</h3>
309
317
Only applicable when selectionLimit different from 0. Will close the dropdown when selection reaches the specified selectionLimit
310
318
</ td >
311
319
</ tr >
320
+ < tr >
321
+ < td > sortByDisplayProperty</ td >
322
+ < td > false</ td >
323
+ < td > boolean</ td >
324
+ < td >
325
+ Will sort the options by the displayProperty
326
+ </ td >
327
+ </ tr >
312
328
</ tbody >
313
329
</ table >
314
330
</ div >
You can’t perform that action at this time.
0 commit comments