Aboelseoud Aboelseoud - 7 months ago 138
Javascript Question

How can I make bootstrap multiselect optgroups collapse by default?

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

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 );