If you have technical questions, please create a support ticket in the DevExpress Support Center.
Bind the Component to Data
To bind the component to data, use one of these properties:
-
items[]
Accepts a local data array (see the Simple JavaScript Lookup code below). -
dataSource
Accepts a local data array or a DataSource object. This object works with local and remote arrays and allows you to shape data. In this demo, a DataSource instance is configured to group a local array of objects (see the Grouped JavaScript Lookup code below).
Both properties work with arrays of primitives or objects. If you use objects, specify the following properties:
-
valueExpr
A data field that contains unique values used to identify items. -
displayExpr
A data field whose values should be displayed in the drop-down list.
When a user selects an item, the JavaScript Lookup component saves the corresponding value from the valueExpr data field in the value property. You can also specify the value property in code to preselect an item as shown in the Simple JavaScript Lookup use case.
Group Data
You can group data items in the drop-down list.
If the data source contains ungrouped data items, use the DataSource's group property to specify the data field to group by.
The JavaScript Lookup component can also work with initially grouped data items. In this case, the data array should contain objects with the key and items fields:
let dataSource = [{
key: "Group 1", // Group caption
items: [ // Items in Group 1
{ /* ... */ },
{ /* ... */ }
]
}, {
key: "Group 2",
items: [
{ /* ... */ },
{ /* ... */ }
]
}];
If data objects are grouped but use other field names, implement the DataSource's map function to create key and items field mappings.
Only one-level grouping is supported.
Regardless of the data source structure, enable the grouped property.
Configure the Drop-Down List
The JavaScript Lookup component uses the Popover component as a drop-down list. To customize the Popover, use the dropDownOptions property. It accepts an object with Popover properties. Alternatively, you can set the usePopover property to false to display lookup items in a pop-up window.