Angular SelectBox - Configure Search Parameters
The SelectBox UI component allows an end user to search through its items. This feature is disabled by default. To enable it, assign true to the searchEnabled property. Use the searchExpr property to specify which data fields should be searched. Assign an array of field names to this property if you need to search several fields.
- <dx-select-box
- [dataSource]="selectBoxData"
- valueExpr="id"
- displayExpr="country"
- [searchEnabled]="true"
- [searchExpr]="['country', 'capital']">
- </dx-select-box>
- import { DxSelectBoxModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- selectBoxData = [
- { id: 1, country: "Afghanistan", capital: "Kabul" },
- { id: 2, country: "Albania", capital: "Tirana" },
- // ...
- ];
- }
- @NgModule({
- imports: [
- // ...
- DxSelectBoxModule
- ],
- // ...
- })
When a user types a string in the input field, the SelectBox suggests all items that contain this string. Assign 'startswith' to the searchMode property if you want the SelectBox to suggest only those items that start with the input string.
- <dx-select-box
- [dataSource]="selectBoxData"
- valueExpr="id"
- displayExpr="country"
- [searchEnabled]="true"
- searchExpr="country"
- searchMode="startswith">
- </dx-select-box>
- import { DxSelectBoxModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- selectBoxData = [
- { id: 1, country: "Afghanistan", capital: "Kabul" },
- { id: 2, country: "Albania", capital: "Tirana" },
- // ...
- ];
- }
- @NgModule({
- imports: [
- // ...
- DxSelectBoxModule
- ],
- // ...
- })
There is a delay between the moment a user finishes typing and the moment the search is executed. To increase or descrease it, use the searchTimeout property. The delay is measured in milliseconds.
- <dx-select-box
- [dataSource]="selectBoxData"
- valueExpr="id"
- displayExpr="country"
- [searchEnabled]="true"
- searchExpr="country"
- [searchTimeout]="1000">
- </dx-select-box>
- import { DxSelectBoxModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- selectBoxData = [
- { id: 1, country: "Afghanistan", capital: "Kabul" },
- { id: 2, country: "Albania", capital: "Tirana" },
- // ...
- ];
- }
- @NgModule({
- imports: [
- // ...
- DxSelectBoxModule
- ],
- // ...
- })
The SelectBox UI component starts searching after a user has typed at least one character by default. Use the minSearchLength property to increase the number of characters that triggers the search.
- <dx-select-box
- [dataSource]="selectBoxData"
- valueExpr="id"
- displayExpr="country"
- [searchEnabled]="true"
- searchExpr="country"
- [minSearchLength]="3">
- </dx-select-box>
- import { DxSelectBoxModule } from "devextreme-angular";
- // ...
- export class AppComponent {
- selectBoxData = [
- { id: 1, country: "Afghanistan", capital: "Kabul" },
- // ...
- ];
- }
- @NgModule({
- imports: [
- // ...
- DxSelectBoxModule
- ],
- // ...
- })
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.