DevExtreme React - Configure Search Parameters
The Lookup widget allows a user to search through its items. Moreover, the widget offers suggestions while the user types a value into the search box. Usually, the data field that provides suggestions is the same data field that is searched for the typed value. If there are two different fields, assign the field providing suggestions to the valueExpr option and the field to be searched to the searchExpr option. Assign an array of field names to the searchExpr option if you need to search several fields.
jQuery
var lookupData = [ { country: "Afghanistan", capital: "Kabul" }, { country: "Albania", capital: "Tirana" }, // ... ]; $(function() { $("#lookupContainer").dxLookup({ dataSource: lookupData, valueExpr: 'country', displayExpr: 'country', searchExpr: 'capital', placeholder: 'Select country' }); });
Angular
<dx-lookup [dataSource]="lookupDataSource" valueExpr="country" displayExpr="country" searchExpr="capital" placeholder="Select country"> </dx-lookup>
import { DxLookupModule } from "devextreme-angular"; // ... export class AppComponent { lookupDataSource = [ { country: "Afghanistan", capital: "Kabul" }, { country: "Albania", capital: "Tirana" }, // ... ]; } @NgModule({ imports: [ // ... DxLookupModule ], // ... })
The Lookup widget can provide suggestions in two different modes: 'contains' (by default) and 'startswith'. You can use the searchMode option to change the mode. You can also use the searchPlaceholder option to specify a placeholder for an empty search box.
jQuery
var lookupData = [ { country: "Afghanistan", capital: "Kabul" }, { country: "Albania", capital: "Tirana" }, // ... ]; $(function() { $("#lookupContainer").dxLookup({ dataSource: lookupData, valueExpr: 'country', displayExpr: 'country', searchMode: 'startswith', searchPlaceholder: 'Type country name' }); });
Angular
<dx-lookup [dataSource]="lookupDataSource" valueExpr="country" displayExpr="country" searchMode="startswith" searchPlaceholder="Type country name"> </dx-lookup>
import { DxLookupModule } from "devextreme-angular"; // ... export class AppComponent { lookupDataSource = [ { country: "Afghanistan", capital: "Kabul" }, { country: "Albania", capital: "Tirana" }, // ... ]; } @NgModule({ imports: [ // ... DxLookupModule ], // ... })
The Lookup widget starts providing suggestions once an end user types the first character by default. Use the minSearchLength option to increase the number of characters that triggers suggestions.
jQuery
$(function() { $("#lookupContainer").dxLookup({ // ... minSearchLength: 3 }); });
Angular
<dx-lookup ... [minSearchLength]="3"> </dx-lookup>
import { DxLookupModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxLookupModule ], // ... })
There is a delay between the moment a user finishes typing and the moment the Lookup starts providing suggestions. To increase or descrease it, use the searchTimeout option. The delay is measured in milliseconds.
jQuery
$(function() { $("#lookupContainer").dxLookup({ // ... searchTimeout: 500 }); });
Angular
<dx-lookup ... [searchTimeout]="500"> </dx-lookup>
import { DxLookupModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxLookupModule ], // ... })
The Lookup widget also clears previous search results before the drop-down menu is displayed by default. Assign false to the cleanSearchOnOpening option to keep them.
jQuery
$(function() { $("#lookupContainer").dxLookup({ // ... cleanSearchOnOpening: false }); });
Angular
<dx-lookup ... [cleanSearchOnOpening]="false"> </dx-lookup>
import { DxLookupModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxLookupModule ], // ... })
Assign false to the searchEnabled option if you need to disable searching.
jQuery
$(function() { $("#lookupContainer").dxLookup({ // ... searchEnabled: false }); });
Angular
<dx-lookup ... [searchEnabled]="false"> </dx-lookup>
import { DxLookupModule } from "devextreme-angular"; // ... export class AppComponent { // ... } @NgModule({ imports: [ // ... DxLookupModule ], // ... })
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.