Reputation: 1182
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.
Upvotes: 3
Views: 6209
Reputation: 1714
I am extending from @Shashi's answer and @MarkosyanArtur's comment 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(); }
})
Upvotes: 3
Reputation: 1182
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();
}
})
Upvotes: 5