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

Commit 16ec963

Browse files
committed
Added search to the directive, added example for search
1 parent 2c4ca0b commit 16ec963

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

angularjs-dropdown-multiselect.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co
2121
template += '<li><a data-ng-click="selectAll()"><span class="glyphicon glyphicon-ok"></span> Check All</a>';
2222
template += '<li><a data-ng-click="deselectAll();"><span class="glyphicon glyphicon-remove"></span> Uncheck All</a></li>';
2323
template += '<li class="divider"></li>';
24+
template += '<li ng-show="settings.enableSearch"><input type="text" class="form-control" ng-model="searchFilter" /></li>';
25+
template += '<li ng-show="settings.enableSearch" class="divider"></li>';
26+
template += '<li data-ng-repeat="option in watchedOptions | filter: searchFilter"><a ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))">';
2427

2528
if(checkboxes)
2629
{
27-
template += '<li data-ng-repeat="option in watchedOptions"><a ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))"><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></li>';
30+
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>';
2831
}
2932
else {
30-
template += '<li data-ng-repeat="option in watchedOptions"><a ng-click="setSelectedItem(getPropertyForObject(option,settings.idProp))"><span data-ng-class="{\'glyphicon glyphicon-ok\': isChecked(getPropertyForObject(option,settings.idProp))}"></span> {{getPropertyForObject(option, settings.displayProp)}}</a></li>';
33+
template += '<span data-ng-class="{\'glyphicon glyphicon-ok\': isChecked(getPropertyForObject(option,settings.idProp))}"></span> {{getPropertyForObject(option, settings.displayProp)}}</a>';
3134
}
3235

36+
template += '</li>';
37+
3338
template += '</ul>';
3439
template += '</div>';
3540

@@ -52,13 +57,16 @@ directiveModule.directive('ngDropdownMultiselect', ['$filter', '$document', '$co
5257
$scope.watchedOptions = angular.copy($scope.options);
5358
}, true);
5459

60+
$scope.searchFilter = '';
61+
5562
$scope.settings = {
5663
dynamicTitle: true,
5764
defaultText: 'Select',
5865
closeOnBlur: true,
5966
displayProp: 'label',
6067
idProp: 'id',
61-
externalIdProp: 'id'};
68+
externalIdProp: 'id',
69+
enableSearch: false};
6270

6371
angular.extend($scope.settings, $scope.extraSettings || []);
6472

0 commit comments

Comments
 (0)