Filter DataSource Manually
The Kendo UI DropDownList has a built-in detection mechanism that checks whether the data is filtered or not.
The widget uses this information to decide when to persist the selected value that does not exist in the source. When the source is manually filtered, the widget loses the details about the state of the DataSource, which might lead to inconsistent behavior.
The following example demonstrates how to manually filter the dataSource
instance of the DropDownList.
<div id="example">
<div class="demo-section k-header">
<h4>DropDownList</h4>
<select id="dropdownlist"></select>
</div>
<script>
$(function() {
var dropdownlist = $("#dropdownlist").kendoDropDownList({
dataTextField: "name",
dataValueField: "value",
dataSource: {
data: [{ name: "One", value: 1 }, { name: "Two", value: 2 }]
}
}).data('kendoDropDownList');
//Filter the source manually
dropdownlist.dataSource.filter({
field: 'value',
operator: 'eq',
value: 1
});
<!-- IMPORTANT: Update filter state of the widget -->
dropdownlist.listView.setDSFilter(dropdownlist.dataSource.filter());
dropdownlist.value(1);
});
</script>
</div>
See Also
- JavaScript API Reference of the DropDownList
- How to Automatically Adjust the Width of a DropDownList
- How to Create DropDownLists with Long Items
- How to Detect Wrapper Focus Events
- How to Move the Group Label on Top of Items
- How to Prevent Popup Closure on Scroll
- How to Remove Items
- How to Set DataSource Dynamically
- How to Update MVVM Bound Models on Load
- How to Validate DropDownLists by Using Required Attributes
For more runnable examples on the Kendo UI DropDownList, browse its How To documentation folder.