Bootstrap multiselect select all checked by default
Asked Answered
K

2

13

i use bootstrap-multiselect (v0.9.8) with option

 includeSelectAllOption: true 

it is posible that select all to be checked by default when page is loaded?

thx.

Kantor answered 23/10, 2014 at 10:4 Comment(0)
R
31

The following is taken from http://davidstutz.github.io/bootstrap-multiselect/, and I am currently using this solution with bootstrap 3.3.1 and bootstrap-multiselect v0.9.8 Be sure to add the false parameter to the 'selectAll' function as that permits you to select all the options without first opening the dropdown.

Example HTML:

<select class="multiselect" id="my-multi-select" name="options[]" multiple="multiple">
    <option>1</option>
    <option>2</option>
</select>

Example javascript:

$(function() {

    $('#my-multi-select').multiselect({
        includeSelectAllOption: true
    });

    $("#my-multi-select").multiselect('selectAll', false);
    $("#my-multi-select").multiselect('updateButtonText');

});
Rego answered 23/12, 2014 at 19:32 Comment(3)
Thank you, you saved my day by $("#my-multi-select").multiselect('updateButtonText');Dismember
This does not seem to work. The checkbox "Select all" remains unchecked.Intersexual
Can you list what versions you are using and the code snippets?Rego
C
0

With bootstrap-select V.1.12.4, the solution is simpler:

Example HTML:

<select class="selectpicker" id="my-multi-select" name="options[]" multiple>
    <option>1</option>
    <option>2</option>
</select>

Example javascript:

$(function() {
    $('#my-multi-select').selectpicker({
    });
    $("#my-multi-select").selectpicker('selectAll');
});
Cyclopropane answered 18/3, 2018 at 17:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.