diff --git a/index.html b/index.html
index c0995bf0..a624008c 100644
--- a/index.html
+++ b/index.html
@@ -246,6 +246,10 @@
Examples
$('#example53-deselect').on('click', function() {
$('#example53').multiselect('deselect', 'cheese');
});
+
+ $('#example54').multiselect({
+ enableClickableOptGroups: true
+ });
});
@@ -524,6 +528,28 @@ Examples
Option groups and options without any group are supported simultaneously.
+
+
+
+ |
+
+ Use enableClickableOptGroups to make optgroup headers clickable to select / deselect all options inside an optgroup.
+ |
+
|
+
+
+ enableClickableOptGroups |
+
+ Set to true to make optgroup headers clickable to select/deselect options.
+ |
+
+
+<script type="text/javascript">
+$(document).ready(function() {
+ $('.multiselect').multiselect({
+ enableClickableOptGroups: true
+ });
+});
</script>
|
diff --git a/js/bootstrap-multiselect.js b/js/bootstrap-multiselect.js
index 3e21e407..f9082018 100644
--- a/js/bootstrap-multiselect.js
+++ b/js/bootstrap-multiselect.js
@@ -242,6 +242,7 @@
selectAllValue: 'multiselect-all',
enableFiltering: false,
enableCaseInsensitiveFiltering: false,
+ enableClickableOptGroups: false,
filterPlaceholder: 'Search',
// possible options: 'text', 'value', 'both'
filterBehavior: 'text',
@@ -527,6 +528,26 @@
event.preventDefault();
}
}, this));
+
+ if(this.options.enableClickableOptGroups && this.options.multiple) {
+ $('li.group', this.$ul).on('click', $.proxy(function(event) {
+ event.stopPropagation();
+
+ var group = $(event.target).parent();
+
+ // Search all option in optgroup
+ var $options = group.nextUntil('li.group');
+
+ // check or uncheck items
+ var allChecked = true;
+ var optionInputs = $options.find('input');
+ optionInputs.each(function() {
+ allChecked = allChecked && $(this).prop('checked');
+ });
+
+ optionInputs.prop('checked', !allChecked).trigger('change');
+ }, this));
+ }
},
/**