I am using the selectpicker plugin. Now I am trying to select all the options by default, or at least a button to select all without the need of click in the dropdown.
Currently the demo only works if the dropdown is clicked and after that, click the button.
Any idea?
$('.selectpicker').selectpicker();
$(".btn_clk").click(function () {
$('.selectpicker').selectpicker('selectAll');
});
http://jsfiddle.net/tpnw96ed/
.selectpicker('refresh')To programmatically update a select with JavaScript, first manipulate the select, then use the refresh method to update the UI to match the new state.
selectpicker("destroy"); $('select#pause' + _week + _day). selectpicker("destroy"); In other plugins if you use destroy, it shows the original element again. Is this an issue in the boostrap select plugin or is there another way to remove the bootstrap select and reshow the original select.
Select Picker is a jQuery plugin supporting work with select boxes. It extends the default possibilities of select boxes with a new range of features.
selectpicker'). selectpicker({ style: 'btn-info', size: 4 }); }); Your script is declared and therefore executed before the <select class="selectpicker"> -declaration, causing bootstrap-select never being initialized opon . selectpicker (selectpicker doesnt exists when the script is runned).
There is default way to add Select All and Deselect All buttons to selectpicker now. You should use option data-actions-box="true"
to enable buttons and data-select-all-text="Select all buttton name" data-deselect-all-text="Deselect all button name"
to rename them
You can open/close the Selectpicker before/after clicking the button:
$(".btn_clk").click(function () {
$('.dropdown-menu').css("display","block");
$('.selectpicker').selectpicker('selectAll');
$('.dropdown-menu').css("display","none");
});
Edit: You will also need to add the following to manually trigger the dropdown on clicks after a selectAll:
$('.selectpicker').click(function () {
if($('.dropdown-menu').css("display") == "block") $('.dropdown-menu').css("display","none");
else $('.dropdown-menu').css("display","block");
});
JSFIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With