5

我正在寻找设置 KendoUI 下拉列表宽度的最佳方法 - 通过 Kendo HTML Helper。

@(Html.Kendo().DropDownList()
    .Name("ddlAccount")
    .DataTextField("Name")
    .DataValueField("Id")
    //This doesn't work, it styles the hidden input instead of the ddl
    .HtmlAttributes(new {style="width:200px;"})
)

我正在设置 DropDownList 的宽度,但请注意在生成的 HTML 中,200 像素的宽度是在隐藏文本输入上设置的,而不是下拉列表:

<span aria-busy="false" aria-readonly="false" aria-disabled="false" aria-owns="ddlAccount_listbox" tabindex="0" aria-expanded="false" aria-haspopup="true" role="listbox" class="k-widget k-dropdown k-header styled_select" style="" unselectable="on" aria-activedescendant="ddlAccount_option_selected">

<span class="k-dropdown-wrap k-state-default">
    <span class="k-input">Choice One</span>
    <span class="k-select">
        <span class="k-icon k-i-arrow-s">select</span>
    </span>
</span>
<input id="ddlAccount" name="ddlAccount" style="width: 200px; display: none;" type="text" data-role="dropdownlist">

...所以生成的 DropDownList 仍然水平和垂直滚动,这是我不想要的。

4

4 回答 4

15

@Html.Kendo().DropDownList().HtmlAttributes(new { style = "width:300px" })在服务器端为我工作并记录在http://docs.kendoui.c​​om / 上。可能不会那么久。

于 2013-06-15T12:04:52.197 回答
2

使用 js,来自剑道网站:

// get reference to the DropDownList
var dropdownlist = $("#size").data("kendoDropDownList");
// set width of the DropDownList
dropdownlist.list.width(500);

提琴手

于 2013-04-29T17:54:08.837 回答
1

只是想我会添加到这个,因为它确实帮助了我......

如果您想应用将列表的宽度扩展到输入宽度之外的东西,您可以使用 jQuery 选择器和 css 类来执行此操作。

注意:这适用于组合框,但应该同样适用于下拉列表

所以你添加这个

   @(Html.Kendo().ComboBoxFor(m => m.UserId)
      ...
      .HtmlAttributes(new { @class = "wideList" })
   )

然后添加一段 Javascript 来执行此操作:

$(document).ready(function () {

 $("input[data-role=\"combobox\"].wideList").each(function () {
    var combo = $(this).data("kendoComboBox");
    combo.list.width(400);
 });

});

更进一步,您实际上可以通过在定义下拉列表时指定宽度来使其更通用:

@(Html.Kendo().ComboBoxFor(m => m.UserId)
   ...
   .HtmlAttributes(new { @class = "wideList", listWidth = "400" })
)

然后是更通用的javascript:

$(document).ready(function () {
  $("input[data-role=\"combobox\"].wideList").each(function () {
    var combo = $(this).data("kendoComboBox");
    var width = $(this).attr('listWidth');
    combo.list.width(width);
  });
});
于 2013-10-31T12:11:19.037 回答
-1

干得好:

$("#Dropdopwnlist").kendoDropDownList().parent().css("width", "200%");

简单,花了一个小时后它对我有用!

于 2016-07-22T15:09:36.003 回答