Feel free to share demo-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Backend API
x
DevExtreme.MVC.Demos.ViewModels.SelectBoxViewModel
<div id="selectbox-demo">
<div class="widget-container">
<div class="dx-fieldset">
<div class="dx-fieldset-header">SearchBox</div>
<div class="dx-field">
<div class="dx-field-label">Product</div>
<div class="dx-field-value">
Html.DevExtreme().SelectBox() (
.ID("search-box")
.InputAttr("aria-label", "Product")
.DataSource(d => d
.Mvc()
.LoadAction("GetItems")
.LoadMode(DataSourceLoadMode.Raw)
.Key("ID")
)
.DisplayExpr("Name")
.ValueExpr("ID")
.SearchEnabled(true)
)
</div>
</div>
</div>
<div class="dx-fieldset">
<div class="dx-fieldset-header">EditBox</div>
<div class="dx-field">
<div class="dx-field">
<div class="dx-field-label">Product</div>
<div class="dx-field-value">
Html.DevExtreme().SelectBox() (
.DataSource(d => d.WebApi()
.Controller("SelectBoxEditing")
.LoadMode(DataSourceLoadMode.Raw)
.InsertAction(true)
.Key("ID")
)
.InputAttr("aria-label", "Custom Product")
.DisplayExpr("Name")
.ValueExpr("ID")
.AcceptCustomValue(true)
.OnValueChanged("selectBox_valueChanged")
.OnCustomItemCreating("selectBox_customItemCreating")
.Value(0)
)
</div>
</div>
<div class="dx-field current-product">
Current product:
<span class="current-value">
HD Video Player (ID: 0)
</span>
</div>
</div>
</div>
</div>
<div class="options">
<div class="caption">SearchBox Options</div>
<div class="option">
<div>Search Mode</div>
Html.DevExtreme().SelectBox() (
.DataSource(new JS("searchModes"))
.InputAttr("aria-label", "Search Mode")
.Value(new JS("searchModes[0]"))
.OnValueChanged("searchMode_changed")
)
</div>
<div class="option">
<div>Search Expression</div>
Html.DevExtreme().SelectBox() (
.DataSource(new JS("searchExpressions"))
.DisplayExpr("name")
.InputAttr("aria-label", "Search Expression")
.ValueExpr("value")
.Value(new JS("searchExpressions[0].value"))
.OnValueChanged("searchExpr_changed")
)
</div>
<div class="option">
<div>Search Timeout</div>
Html.DevExtreme().NumberBox() (
.Min(0)
.Max(5000)
.Value(200)
.ShowSpinButtons(true)
.Step(100)
.InputAttr("aria-label", "Search Timeout")
.OnValueChanged("searchTimeout_changed")
)
</div>
<div class="option">
<div>Minimum Search Length</div>
Html.DevExtreme().NumberBox() (
.Min(0)
.Max(5)
.Value(0)
.ShowSpinButtons(true)
.InputAttr("aria-label", "Minimum Search Length")
.OnValueChanged("minSearchLength_changed")
)
</div>
<div class="option">
Html.DevExtreme().CheckBox() (
.Value(false)
.Text("Show Data Before Search")
.OnValueChanged("showDataBeforeSearch_changed")
)
</div>
</div>
</div>
<script>
var searchModes = ["contains", "startswith"];
var searchExpressions = [{
name: "'Name'",
value: "Name"
}, {
name: "['Name', 'Category']",
value: ['Name', 'Category']
}];
function selectBox_valueChanged(data) {
var $result = $(".current-value");
if (data.value !== null) {
var selectedItem = data.component.option('selectedItem');
$result.text(selectedItem.Name + " (ID: " + selectedItem.ID + ")");
} else {
$result.text("Not selected");
}
}
function getSearchBoxInstance() {
return $("#search-box").dxSelectBox("instance");
}
function searchMode_changed(data) {
getSearchBoxInstance().option("searchMode", data.value);
}
function searchExpr_changed(data) {
getSearchBoxInstance().option("searchExpr", data.value);
}
function searchTimeout_changed(data) {
getSearchBoxInstance().option("searchTimeout", data.value);
}
function minSearchLength_changed(data) {
getSearchBoxInstance().option("minSearchLength", data.value);
}
function showDataBeforeSearch_changed(data) {
getSearchBoxInstance().option("showDataBeforeSearch", data.value);
}
function selectBox_customItemCreating(data) {
if (!data.text) {
data.customItem = null;
return;
}
var dataSource = data.component.getDataSource();
var newItem = { Name: data.text };
var result = dataSource.store().insert(newItem);
result.done(function() {
dataSource.reload();
})
data.customItem = result;
}
</script>
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
The following properties help you configure the feature:
- searchExpr
Specifies one or several data fields to search. - searchMode
Specifies whether found items should contain the typed-in string or start with it. - searchTimeout
Specifies the delay between the moment a user stops typing and the moment the search is executed. - minSearchLength
Specifies the minimum number of characters that a user should type in to trigger the search. - showDataBeforeSearch
Specifies whether the SelectBox should display the unfiltered item list until a user have typed in the minimum number of characters (minSearchLength).
Set the acceptCustomValue property to true to allow users to add values to the SelectBox. You should also implement the onCustomItemCreating handler to create new data source entries.