Restrict rows and columns in entityPicker

How can I restrict which columns and rows I see when using the entityPicker on a table?

And at the same time still be able to see all rows and columns when I access the table directly?

Is that possible?

I know I can add a parameter to the query WHERE in <![CDATA[…., but this parameter is global and I can’t reset it when accessing the table directly.

Using Jmix v2.8.1 and IntelliJ 2026.1.1

Hi @pub.reformat982!

Lookup views

Jmix has a dedicated mechanism for this – lookup views.

When the entity_lookup action needs a view, it resolves one in this order:

  1. a view annotated @PrimaryLookupView(Entity.class)
  2. a view with id <entity>.lookup
  3. @PrimaryListView
  4. a view with id <entity>.list

So once you create a Product.lookup view, the picker uses it automatically, while opening the DataGrid from the menu still goes to Product.list with all rows and columns — nothing to reset.

If the filter has to depend on the edited record, set a loader parameter when the lookup opens via withViewConfigurer — this affects only the lookup view, never the standalone list:

productLookupAction.withViewConfigurer(view -> {
    if (view instanceof ProductLookupView lookupView) {
        lookupView.setCategory(getEditedEntity().getCategory());
    }
    // or configure columns visibility
});

// in ProductLookupView (query: ... where e.category = :category)
public void setCategory(Category category) {
    productsDl.setParameter("category", category);
    productsDl.load();
}

Modify List Views

Also you can reuse the very same list view and add the conditions only when it’s opened from an entityPicker.

The view knows how it was opened: when it’s used as a lookup, the framework sets a selection handler on it before the data is loaded. So getSelectionHandler().isPresent() is true only in lookup mode and false on direct navigation. Use that to add your condition in the loader’s BeforeLoadEvent:

@Subscribe(id = "productsDl", target = Target.DATA_LOADER)
public void onProductsDlBeforeLoad(CollectionLoader.BeforeLoadEvent<Product> event) {
    if (getSelectionHandler().isPresent()) {        // opened from an entityPicker
        event.getSource().setCondition(/* some condition*/)
    }
}

Columns can’t be hidden per-mode this way (the grid is the same), but you can toggle productsDataGrid.getColumnByKey("...").setVisible(false) in BeforeShowEvent under the same getSelectionHandler().isPresent() check. If you need very different columns, a separate <entity>.lookup view is cleaner.

Best regards,
Dmitriy

Thanks Dmitriy, I will check out.

-Erik