Filter the MultiSelect DataSource Manually
Environment
Product | Progress Kendo UI MultiSelect for jQuery |
Operating System | Windows 10 64bit |
Visual Studio version | Visual Studio 2017 |
Preferred Language | JavaScript |
Description
How can I manually filter the dataSource
instance of the MultiSelect?
Solution
The Kendo UI MultiSelect 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 achieve the desired scenario.
<div id="example">
<div class="demo-section k-header">
<h4>MultiSelect</h4>
<select id="multiselect" multiple="multiple"></select>
</div>
<script>
$(function() {
var ms = $("#multiselect").kendoMultiSelect({
dataTextField: "name",
dataValueField: "value",
dataSource: {
data: [{ name: "One", value: 1 }, { name: "Two", value: 2 }]
}
}).data('kendoMultiSelect');
//Filter the source manually
ms.dataSource.filter({
field: 'value',
operator: 'eq',
value: 1
});
<!-- IMPORTANT: Update filter state of the widget -->
ms.listView.setDSFilter(ms.dataSource.filter());
ms.value(1);
});
</script>
</div>
See Also
- MultiSelect JavaScript API Reference
- How to Cascade from DropDownList
- How to Filter Values in Widgets Sharing the Same Data
- How to Preselect Items Using MVVM Binding
- How to Select All Values with Single Selection
- How to Use MultiSelect with Bootstrap Modal Window
- How to Wire Blur Event of the Filter Input