简体   繁体   中英

bootstrap multiselect dropdown selected content break in more then one line

i am using bootstrap multiselect dropdown and display all the selected value in dropdown. but now i have many values so, i want to break it in more than one line. now i have like it in image below.

在此处输入图片说明

see select group option i want that selected content to break in more then one line. i have following jquery code for it.

<script type="text/javascript">
$(document).ready(function() {
    $('#fk_group_id').multiselect({
        includeSelectAllOption: true,
        enableFiltering: true,

        buttonText: function(options, select) {
        if (options.length == 0) {
            return 'Select Groups';
        }
        else {
            var selected = '';
            options.each(function() {
                selected += $(this).text() + ', ';
            });
            return selected.substr(0, selected.length -2);
        }
    },
    });
    $('.btn-group').css({"min-width":"35%"});
});
</script>

please help me.

You may want to use

https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.min.js

Add this CSS to break the selection

.multiselect-selected-text{
  display: inline-block;
  max-width: 100%;
  word-break: break-all;
  white-space: normal;
}

SNIPPET

 $(document).ready(function() { $('#example-getting-started').multiselect({ includeSelectAllOption: true, enableFiltering: true, buttonText: function(options, select) { if (options.length == 0) { return 'Select Groups'; } else { var selected = ''; options.each(function() { selected += $(this).text() + ', '; }); return selected.substr(0, selected.length -2); } }, }); }); 
 .multiselect-selected-text{ display: inline-block; max-width: 100%; word-break: break-all; white-space: normal; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-multiselect/0.9.13/js/bootstrap-multiselect.min.js"></script> <!-- Build your select: --> <select id="example-getting-started" multiple="multiple"> <option value="cheese">Cheese</option> <option value="tomatoes">Tomatoes</option> <option value="mozarella">Mozzarella</option> <option value="mushrooms">Mushrooms</option> <option value="pepperoni">Pepperoni</option> <option value="onions">Onions</option> <option value="cheese">Cheese</option> <option value="tomatoes">Tomatoes</option> <option value="mozarella">Mozzarella</option> <option value="mushrooms">Mushrooms</option> <option value="pepperoni">Pepperoni</option> <option value="onions">Onions</option> <option value="cheese">Cheese</option> <option value="tomatoes">Tomatoes</option> <option value="mozarella">Mozzarella</option> <option value="mushrooms">Mushrooms</option> <option value="pepperoni">Pepperoni</option> <option value="onions">Onions</option> </select> 

You could achieve this with the following CSS settings:

.multiselect {
    white-space: normal !important;
    max-width: 200px;
}

white-space:normal lets the text inside the button wrap again and with max-width you can set the maximum width the button should grow to.

See this JSFiddle .

IMHO it is not possible to break the lines using buttonText , eg by inserting <br/> . You can see from the source code of bootstrap-multiselect that in updateButtonText the result of buttonText is inserted using jQuery's html() method and so a <br/> is converted to &lt;br/&gt; .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM