This is possible if you return Select2 with a hidden input element - instead of the select element.
To make a group selection, you must specify "id", but it seems to be an empty string. Then you can use the "select2-selection" event to prevent the group from being selected, and instead select its child parameters.
In addition, a query function can be provided to prevent a group parameter from appearing in the list after all its child parameters have been selected.
If you have parameters defined as follows:
var FRUIT_GROUPS = [ { id: '', text: 'Citrus', children: [ { id: 'c1', text: 'Grapefruit' }, { id: 'c2', text: 'Orange' }, { id: 'c3', text: 'Lemon' }, { id: 'c4', text: 'Lime' } ] }, { id: '', text: 'Other', children: [ { id: 'o1', text: 'Apple' }, { id: 'o2', text: 'Mango' }, { id: 'o3', text: 'Banana' } ] } ];
You can customize your Select2 as follows:
$('#fruitSelect').select2({ multiple: true, placeholder: "Select fruits...", data: FRUIT_GROUPS, query: function(options) { var selectedIds = options.element.select2('val'); var selectableGroups = $.map(this.data, function(group) { var areChildrenAllSelected = true; $.each(group.children, function(i, child) { if (selectedIds.indexOf(child.id) < 0) { areChildrenAllSelected = false; return false;
jsfiddle
Here is jsfiddle without the query function, where group parameters still appear when all their child parameters are selected.