Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select2 dropdown auto width not working properly

I am using select2 to set the dropdownautowidth to true on my SharePoint search page and it works perfectly on page load for the first time. After i search for some keyword, the page loads with search results and then dropdownautowidth is not setting true by somehow. I am using $('#ddlCategory').select2({dropdownAutoWidth : true}); statement on my document.ready function.

Any help is appreciated.

like image 621
Surendra Chatakondu Avatar asked Jan 06 '14 13:01

Surendra Chatakondu


3 Answers

This worked for me:

$('select').select2({
    dropdownAutoWidth : true,
    width: 'auto'
})
like image 115
Mawi Avatar answered Nov 18 '22 04:11

Mawi


you need to quote it, like:

$('#ddlCategory').select2({dropdownAutoWidth: 'true'});

this works for me.

like image 31
7heaven Avatar answered Nov 18 '22 05:11

7heaven


In select2 4.0.0 this will not work for me, either. I use this workaround:

$('select').select2();

The css:

select + .select2-container {
  width: 100% !important;
}
like image 12
Frank Avatar answered Nov 18 '22 03:11

Frank