Datagrid change editor for inline editing

When I set a column in a dataGrid editable, JMix is choosing EntityCombox for any association.

I would like to use the entityPicker.

What is the best way to resolve this ?

Best regards

Felix

Hello!

Could you clarify which Jmix version do you use?

Hi Roman

Sorry for the missing information. JMix Version 2.1.1

IntelliJ IDEA 2023.3.2 (Ultimate Edition)
Build #IU-233.13135.103, built on December 20, 2023

Runtime version: 17.0.9+7-b1087.9 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

You can do it setting custom component for inline editing (see dataGrid :: Jmix Documentation). For instance:

@ViewComponent
private DataGrid<OrderLine> orderLinesDataGrid;
@ViewComponent
private CollectionContainer<Order> ordersDc;
@Autowired
private UiComponents uiComponents;

@Subscribe
public void onInit(final InitEvent event) {
    orderLinesDataGrid.getEditor().setColumnEditorComponent("order", context -> {
        EntityComboBox<Order> comboBox = uiComponents.create(EntityComboBox.class);
        comboBox.setItems(ordersDc);
        comboBox.setValueSource(context.getValueSourceProvider().getValueSource("order"));
        comboBox.setWidthFull();
        comboBox.setStatusChangeHandler((Consumer) context.getStatusHandler());
        return comboBox;
    });
}
2 Likes

Perfect reply !
Thank you.

I did miss the CollectionContainer with the StatusChangeHandler in the doc.

In the EntityComboBox it is possible to select an entry by typing the searched item and to take the value of the found entry with the arrow down key. Is there a way to change this arrow down key with the enter key ?

Could you clarify do you want to use enter key to moving on items in dropdown list instead of arrow keys?

In an empty EntityComboBox i enter the key of an enitity of the items which will be displayed below the EntityComboBox.
grafik

grafik

To select at this point this entity, I need to select it with the arrow_down key and when I move with tab to the next field the reference for this entity will be stored.

In this application people work only with a reduced keyboard, it would be great, to have the ability to change this arrow_down key for selecting this entity with the enter key.

Unfortunately, component does not enable changing interactions keys. You can try to add shortcut to the field, may be that will help to detect one option in dropdown list and select it.

Shortcuts.addShortcutListener(entityComboBox, () -> {
                        // When field is in focus and ENTER key is pressed
                    }, Key.ENTER)
                    .listenOn(entityComboBox);

Thank you for your try which is working the way you describe.

BUT the problem is, that the field is not in focus; it is the only one in the selection …

Any idea how to catch that one :roll_eyes: