Jmix has a dedicated mechanism for this – lookup views.
When the entity_lookup action needs a view, it resolves one in this order:
a view annotated @PrimaryLookupView(Entity.class)
a view with id <entity>.lookup
@PrimaryListView
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.