lookup

Specifies options of a lookup column.

Type: Object
Default Value: undefined

A lookup column restricts the set of values that can be chosen when a user edits or filters the column. In a lookup column, each cell is a drop-down menu. You can use a lookup column when you need to substitute displayed values for required values. For example, consider that you have two arrays of objects: drivers and buses.

JavaScript
var drivers = [
    { driverID: 1, firstName: 'John', lastName: 'Smith', busID: 2 },
    { driverID: 2, firstName: 'Lizzy', lastName: 'Cook', busID: 1 },
    { driverID: 3, firstName: 'Brian', lastName: 'Hawkins', busID: 3 }
];

var buses = [
    { busID: 1, plates: '123456' },
    { busID: 2, plates: 'AB-1234' },
    { busID: 3, plates: 'CD-9876' }
];

All drivers have the busID field, which refers to a bus. If drivers is the main dataSource, the Bus ID column displays bus IDs, which provides little information to a user. It will be more useful to display bus license plates instead of IDs. For this, the buses array must be set as a lookup dataSource for the Bus ID column. Then, the names of data fields must be assigned to the valueExpr and displayExpr options. Values from the valueExpr data field will be replaced with values from the displayExpr data field.

JavaScript
$(function() {
    $("#treeListContainer").dxTreeList({
        dataSource: drivers,
        // ...
        columns: [{
            dataField: 'busID',
            lookup: {
                dataSource: buses,
                valueExpr: 'busID',
                displayExpr: 'plates'
            }
        }]
    });
});

With this code, the Bus ID column contains license plates instead of IDs. Moreover, the user can choose a plate number from the drop-down menu when editing cells or applying a filter to this column.

allowClearing

Specifies whether a user can nullify values of the lookup column.

Type: Boolean
Default Value: false

Set this option to true only if your data source accepts null values. If you do, all cells of the lookup column in the editing state will have a button that nullifies the cell's value.

dataSource

Specifies the data source for the lookup column.

Type: Array|DataSource configuration| function(options)
Function parameters:
options: Object
The settings of a row.
Object structure:
data: Object
The data of the row.
key: any
The key value of the row.
Default Value: undefined

This option accepts one of the following.

  • Array of Objects
    A simple JavaScript array containing a collection of plain objects.

  • DataSource Configuration Object
    A configuration object of the DataSource. Learn more about the DataSource and the DevExtreme Data Layer concept from the Data Layer topic.

    NOTE
    When using a CustomStore for the lookup data source, you are required to implement the load and byKey functions.
  • Function
    A function that returns either an array of objects or a DataSource configuration object.

The lookup data source must contain fields assigned to the valueExpr and displayExpr options.

See Also

displayExpr

Specifies the data source field whose values must be displayed.

Type: String| function(data)
Function parameters:
data: Object
The data of a row.
Default Value: undefined

Values from this field will replace the values from the valueExpr field. If you need to combine the value to be displayed from several fields, set the displayExpr option to a function that returns the required value.

valueExpr

Specifies the data source field whose values must be replaced.

Type: String
Default Value: undefined

Values from this field will be replaced with values from the displayExpr field.