javascript - Select/dropdown with customized option labels -
just want ask here, although searches did, answer ever found customizing select's option not possible.
however stumbled upon page customized option on it
i thinking code of above might this
<select> <option> <span style="float:left;">option 1</span> <span style="float:right;">test</span> </option> </select>
but mentioned, customizing such option not possible @ all.
so want know how achieve such thing? there such javascript/jquery select/dropdown plugins out there can provide such option look?
there bootstrap selectpicker plugin. allows achieve this.
in bootstrap selectpicker there option add subtext below.
<select class="selectpicker" data-size="5"> <option data-subtext="heinz">ketchup</option> </select>
you can add button add new option in selectpicker <option data-content="<span class='btn btn-link'><i class='fa fa-plus text-primary'></i> add new</span>"></option>
example:
<select class="selectpicker" data-size="5"> <option data-subtext="heinz">ketchup</option> <option data-content="<span class='btn btn-link'><i class='fa fa-plus text-primary'></i> add new</span>"></option> </select>
after including html code initialise selectpicker jquery below.
$('.selectpicker').selectpicker({ size: 4 });
there lots options selectpicker plugin. please refer link more details.
if want display subtext first text on dropdown can use below example.
<select class="selectpicker" data-size="5"> <option data-subtext="<span class='leftmen pull-left'>sub text</span>">main text </option> <option data-content="<span class='btn btn-link'><i class='fa fa-plus text-primary'></i> add new</span>"></option> </select>
the leftmen
class defined below.
.leftmen{ padding-top: 3px; padding-right:5px; }
sample screen here (note not output of code have written here. show behaviour of selectpicker plugin):
demo:
$('.selectpicker').selectpicker(); //initialize selectpicker $(".muted.text-muted").addclass("pull-right"); //after initialization add pull-right class class 'muted text-muted' sub-text displayed on right.
.bootstrap-select.btn-group .dropdown-menu li span.text { display: inline-block; width: 100% !important; //this necessary change default class adding line of code set width of option 100% sub-text pulled right }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/js/bootstrap-select.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.3/css/bootstrap-select.min.css" rel="stylesheet"/> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <select class="selectpicker" data-size="5"> <option data-content="<span class='btn btn-link'><i class='fa fa-plus text-primary'></i> add new</span>"></option> <option data-subtext="sub text1">main text1 </option> <option data-subtext="sub text2">main text2 </option> <option data-subtext="sub text3">main text3 </option> <option data-subtext="sub text4">main text4 </option> </select>
Comments
Post a Comment