JavaScript/jQuery Lookup - Configure Search Parameters

NOTE
Searching works when inputting a plain data structure only. However, if you need the searching capability and hierarchical data, transform the plain data using the DataSource's group property.

The Lookup UI component allows a user to search through its items. Moreover, the UI component 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 property and the field to be searched to the searchExpr property. Assign an array of field names to the searchExpr property if you need to search several fields.

JavaScript
  • const lookupData = [
  • { country: "Afghanistan", capital: "Kabul" },
  • { country: "Albania", capital: "Tirana" },
  • // ...
  • ];
  •  
  • $(function() {
  • $("#lookupContainer").dxLookup({
  • dataSource: lookupData,
  • valueExpr: 'country',
  • displayExpr: 'country',
  • searchExpr: 'capital',
  • placeholder: 'Select country'
  • });
  • });

The Lookup UI component can provide suggestions in two different modes: 'contains' (by default) and 'startswith'. You can use the searchMode property to change the mode. You can also use the searchPlaceholder property to specify a placeholder for an empty search box.

JavaScript
  • const lookupData = [
  • { country: "Afghanistan", capital: "Kabul" },
  • { country: "Albania", capital: "Tirana" },
  • // ...
  • ];
  •  
  • $(function() {
  • $("#lookupContainer").dxLookup({
  • dataSource: lookupData,
  • valueExpr: 'country',
  • displayExpr: 'country',
  • searchMode: 'startswith',
  • searchPlaceholder: 'Type country name'
  • });
  • });

The Lookup UI component starts providing suggestions once an end user types the first character by default. Use the minSearchLength property to increase the number of characters that triggers suggestions.

JavaScript
  • $(function() {
  • $("#lookupContainer").dxLookup({
  • // ...
  • minSearchLength: 3
  • });
  • });

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 property. The delay is measured in milliseconds.

JavaScript
  • $(function() {
  • $("#lookupContainer").dxLookup({
  • // ...
  • searchTimeout: 500
  • });
  • });

The Lookup UI component also clears previous search results before the drop-down menu is displayed by default. Assign false to the cleanSearchOnOpening property to keep them.

JavaScript
  • $(function() {
  • $("#lookupContainer").dxLookup({
  • // ...
  • cleanSearchOnOpening: false
  • });
  • });

Assign false to the searchEnabled property if you need to disable searching.

JavaScript
  • $(function() {
  • $("#lookupContainer").dxLookup({
  • // ...
  • searchEnabled: false
  • });
  • });
See Also