最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - kendo dropdownlist shows optionlabel in dropdown - Stack Overflow

programmeradmin2浏览0评论

I am using kendodropdown. I used optionLabel = "Actions" and it is displayed as an option in the dropdown how do I ignore it as a value in dropdown.

Is there a way where we can stop or hide optionLabel in kendo dropdownlist to be displayed as an option in the dropdown.

var $dropdownElement = $("<input />");

$dropdownElement.appendTo($dropdownContainer);
$dropdownElement.kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: dropdown.items,
        optionLabel: 'Actions'
})

As of now Actions is displayed as an option in the dropdown please help me to ignore it as a value in dropdown.

I am using kendodropdown. I used optionLabel = "Actions" and it is displayed as an option in the dropdown how do I ignore it as a value in dropdown.

Is there a way where we can stop or hide optionLabel in kendo dropdownlist to be displayed as an option in the dropdown.

var $dropdownElement = $("<input />");

$dropdownElement.appendTo($dropdownContainer);
$dropdownElement.kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: dropdown.items,
        optionLabel: 'Actions'
})

As of now Actions is displayed as an option in the dropdown please help me to ignore it as a value in dropdown.

Share Improve this question asked Oct 28, 2015 at 22:10 ShashiShashi 1,1722 gold badges18 silver badges32 bronze badges 1
  • (As per my knowledge) It is default functionality of drop down list we can not change it. – Jayesh Goyani Commented Oct 29, 2015 at 6:05
Add a ment  | 

2 Answers 2

Reset to default 5

This is the solution that worked well, I am hiding the first element when I click the dropdown.

var $dropdownElement = $("<input />");

$dropdownElement.appendTo($dropdownContainer);
$dropdownElement.kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: dropdown.items,
        optionLabel: 'Actions',
        open: function () { $($dropdownElement).getKendoDropDownList().list.find("li.k-item").first().hide(); 
                }
})

I am extending from @Shashi's answer and @MarkosyanArtur's ment in the same answer. The open event fires every time the user tries to expand the DropDown list. Why not use dataBound event instead? Also, an additional tit-bit, the this specifier links to the ddl itself, therefore;

var $dropdownElement = $("<input />");

$dropdownElement.appendTo($dropdownContainer);
$dropdownElement.kendoDropDownList({
        dataTextField: "text",
        dataValueField: "value",
        dataSource: dropdown.items,
        optionLabel: 'Actions',
        dataBound: function () { this.element.getKendoDropDownList().list.find(".k-list-optionlabel").hide(); }
})
发布评论

评论列表(0)

  1. 暂无评论