Lookup type in Jmix + Datagrid


With CUBA Platform, you could define lookup type as a dropdown for an entity attribute and then it would enable you to use a dropdown instead of a lookup screen in an editable DataGrid. Is there a similar thing available in Jmix already built in or am I missing something?

I’m asking this as the property is not available in the data model designer as it was previously in Cuba.



You should use EntityComboBox instead of LookupField.
For example:

    private DataGrid<User> usersTableGrid;
    private UiComponents uiComponents;
    private CollectionContainer<NewEntity> newEntitiesDc;

    protected void onInit(InitEvent event) {
           usersTableGrid.getColumnNN("newentity").setEditFieldGenerator(userEditor -> {
            EntityComboBox<NewEntity> entityComboBox = uiComponents.create(EntityComboBox.NAME);

            entityComboBox.setValueSource((ValueSource<NewEntity>) userEditor
            return entityComboBox;

More information about EntityComboBox


There is also a declarative way of defining what component to use for selecting an entity in generic mechanisms. It is based on the jmix.ui.entityFieldType and jmix.ui.entityFieldActions properties.

Try to add the following lines to your application.properties:

# component to select app_MyEntity (should implement EntityPicker)
jmix.ui.entityFieldType.app_MyEntity = entityComboBox

# what actions to add to the app_MyEntity selection component
jmix.ui.entityFieldActions.app_MyEntity = entity_lookup, entity_open, entity_clear