I would like to use a kendo drop-down list, which has a fixed size since is constrained by other fields in the page, but when it shows the drop-down items of the list, the drop-down area should resize to the maximum length of the items. Sort of fixed width for the item displayed, but auto width for the drop down list. Something like
|my choice | <-- fixed width displayed on the page
|next choice |
|previous choice | <-- dropdown area to select another item
|dummy |
Is this possible through CSS or drop-down list properties set through jQuery?
What worked for me is to render an extra class on the base element:
Which produced:
With this ExtraLarge class in place, this worked great in FireFox and Chrome:
You can set the width of a DropDown List both using a CSS or using a method.
If the id of you
DropDownList
ismy-dropdown
then you should write:Using CSS
NOTE: We have appended
-list
to the originalid
. The "!important" is important since you want to overwrite original width definition.Using a method
In addition to use
"auto"
for getting the width automatically adjusted to the text, you can use a fixed width:or:
If the id of you DropDownList is my-dropdown then you should write:
Read the explanation below. http://docs.telerik.com/kendo-ui/controls/editors/dropdownlist/how-to/auto-adjust-the-width
Using the following code to be the template of the kendo dropdownlist:
you will initiate the kendoDropDownList using jQuery as follows:
Now, to set this controller to take up the full width, what you have to do, is to set the width of the select element to 100%, or whatever is your desire. e.g.:
OR, is a css file:
The above answer didn't work for me. I have a the advantage of knowing that my dropdown is inside of a div.
I found that the span has the class k-dropdown so I added the CSS