How can I make bootstrap multiselect optgroups collapse by default?

Aboelseoud picture Aboelseoud · Apr 27, 2016 · Viewed 7.4k times · Source

I am using bootstrap's multiselect with enableCollapsibleOptGroups set to true.

What I have now:

enter image description here

I want to have optgroups collapsed by default:

enter image description here

Answer

Aboelseoud picture Aboelseoud · May 6, 2016

David's answer didn't work for me. But these two solutions worked:

Solution 1:

buttonContainer: '<div id="example-enableCollapsibleOptGroups-collapsed-container" />',
onDropdownShown: function() {
                $('#example-enableCollapsibleOptGroups-collapsed-container .caret-container').click();
            },
onDropdownHidden: function() {
                $('#example-enableCollapsibleOptGroups-collapsed-container .caret-container').click();
            }

Solution 2:

buttonContainer: '<div id="example-enableCollapsibleOptGroups-collapsed-container" />'

Then:

setTimeout( function(){ 
    $('#example-enableCollapsibleOptGroups-collapsed-container .caret-container').click();
}  , 2000 );