Skip to content
This repository was archived by the owner on Dec 16, 2019. It is now read-only.

Commit cdaac31

Browse files
committed
Added setting template:
- Type: String - Default: {{getPropertyForObject(option, settings.displayProp)}} - Description: Can be used to modify the appearance of an option in the list, each option is accessible as option. Closes issue #2
1 parent fa27041 commit cdaac31

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

pages/javascripts/pages/home/ExampleCtrl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,16 @@ angular.module('exampleApp').controller('ExampleCtrl', ['$scope', function($scop
189189
selectionLimit: 1
190190
};
191191

192+
$scope.example19model = {};
193+
$scope.example19data = [
194+
{ id: 1, name: "David" },
195+
{ id: 2, name: "Jhon" },
196+
{ id: 3, name: "Lisa" },
197+
{ id: 4, name: "Nicole" },
198+
{ id: 5, name: "Danny" }];
199+
$scope.example19settings = {
200+
template: '<b>{{option.name}}</b>'
201+
};
202+
192203
$scope.customFilter = 'a';
193204
}]);

pages/javascripts/pages/home/home.html

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ <h3>Demo</h3>
657657
</div>
658658
<div class="col-xs-12 col-sm-6">
659659
<h3>The model:</h3>
660-
<pre>{{example17model|json}}</pre>
660+
<pre>{{example18model|json}}</pre>
661661
</div>
662662
</div>
663663
<div class="row">
@@ -680,6 +680,45 @@ <h3>Code</h3>
680680
keyboardControls: true,
681681
enableSearch: true,
682682
selectionLimit: 1
683+
};
684+
</div>
685+
</div>
686+
</div>
687+
</accordion-group>
688+
<accordion-group heading="Custom template per option">
689+
<div class="row">
690+
<div class="col-xs-12 col-sm-6">
691+
<h3>Demo</h3>
692+
Instead of using the default template you can use an own custom temlpate.
693+
<div class="well">
694+
<div>
695+
<div ng-dropdown-multiselect="" options="example19data" selected-model="example19model" extra-settings="example19settings"></div>
696+
</div>
697+
</div>
698+
</div>
699+
<div class="col-xs-12 col-sm-6">
700+
<h3>The model:</h3>
701+
<pre>{{example19model|json}}</pre>
702+
</div>
703+
</div>
704+
<div class="row">
705+
<div class="col-md-12">
706+
<h3>Code</h3>
707+
<div hljs>
708+
// HTML
709+
<div ng-dropdown-multiselect="" options="example19data" selected-model="example19model" extra-settings="example19settings"></div>
710+
711+
// JavaScript
712+
$scope.example19model = {};
713+
$scope.example19data = [
714+
{ id: 1, name: "David" },
715+
{ id: 2, name: "Jhon" },
716+
{ id: 3, name: "Lisa" },
717+
{ id: 4, name: "Nicole" },
718+
{ id: 5, name: "Danny" }
719+
];
720+
$scope.example19settings = {
721+
template: '<b>{{option.name}}</b>'
683722
};
684723
</div>
685724
</div>
@@ -885,6 +924,12 @@ <h2>Settings</h2>
885924
<td>false</td>
886925
<td>When activated the dropdown can be used with the keyboard instead of with the mouse.</td>
887926
</tr>
927+
<tr>
928+
<td>template</td>
929+
<td>String</td>
930+
<td>{{getPropertyForObject(option, settings.displayProp)} }</td>
931+
<td>Can be used to modify the appearance of an option in the list, each option is accessible as option.</td>
932+
</tr>
888933
</tbody>
889934
</table>
890935
<h2>Events</h2>

src/angularjs-dropdown-multiselect.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
var directiveModule = angular.module('angularjs-dropdown-multiselect', []);
44

5+
directiveModule.directive('staticInclude', function ($compile) {
6+
return function (scope, element, attrs) {
7+
var template = attrs.staticInclude;
8+
var contents = element.html(template).contents();
9+
$compile(contents)(scope);
10+
};
11+
});
12+
513
directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$compile', '$parse',
614
function ($filter, $document, $compile, $parse) {
715

@@ -39,9 +47,9 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co
3947
template += '<a role="menuitem" class="option" tabindex="-1" ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))">';
4048

4149
if (checkboxes) {
42-
template += '<div class="checkbox"><label><input class="checkboxInput" type="checkbox" ng-click="checkboxClick($event, getPropertyForObject(option,settings.idProp))" ng-checked="isChecked(getPropertyForObject(option,settings.idProp))" /> {{getPropertyForObject(option, settings.displayProp)}}</label></div></a>';
50+
template += '<div class="checkbox"><label><input class="checkboxInput" type="checkbox" ng-click="checkboxClick($event, getPropertyForObject(option,settings.idProp))" ng-checked="isChecked(getPropertyForObject(option,settings.idProp))" /><div static-include="{{settings.template}}"></div></label></div></a>';
4351
} else {
44-
template += '<span data-ng-class="{\'glyphicon glyphicon-ok\': isChecked(getPropertyForObject(option,settings.idProp))}"></span> {{getPropertyForObject(option, settings.displayProp)}}</a>';
52+
template += '<span data-ng-class="{\'glyphicon glyphicon-ok\': isChecked(getPropertyForObject(option,settings.idProp))}"></span><div static-include="{{settings.template}}"></div></a>';
4553
}
4654

4755
template += '</li>';
@@ -123,7 +131,8 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co
123131
smartButtonMaxItems: 0,
124132
smartButtonTextConverter: angular.noop,
125133
styleActive: false,
126-
keyboardControls: false
134+
keyboardControls: false,
135+
template: '{{getPropertyForObject(option, settings.displayProp)}}'
127136
};
128137

129138
$scope.texts = {

0 commit comments

Comments
 (0)