Insert at selected position in TreeTable

Hi all,

I am using TreeTable to show a hierarchical entity. I would like to insert newly created records at the selected position of the TreeTable. Any idea how can I do this?

Thanks for your help.

Hello @sambill

New entities are added into TreeTable according their hierarchical property. Could you clarify the task?

Regards,
Daniil

Hi Daniil

In the TreeTable, I am selecting a row and click on create button. I managed to configure the editor to consider as parent the selected row. I successfully create a new entry in the hierarchy, however the newly created entry appear at the end of the TreeTable.

Thanks for your help.

Best,
Samy

I’ve tested the case. New entry is added according hierarchy. The solution is used:

@Inject
private TreeTable<Department> departmentsTable;
@Named("departmentsTable.create")
private CreateAction departmentsTableCreate;
@Inject
private ScreenBuilders screenBuilders;
@Inject
private Metadata metadata;

@Subscribe
public void onInit(InitEvent event) {
    departmentsTableCreate.addActionPerformedListener(e -> {
        Department department = metadata.create(Department.class);
        department.setParent(departmentsTable.getSingleSelected());

        Screen editor = screenBuilders.editor(departmentsTable)
                .editEntity(department)
                .build();
        editor.show();
    });
}

Could you share test project to investigate the problem?

Hi Daniil,

Interesting, I tried your code and it works. If you try the following, you won’t see the insert at the right position:

    Screen s = screenBuilders.editor(Category.class, this)
            .editEntity(newCategory)
            .withLaunchMode(OpenMode.DIALOG)
            .build();

Instead of using the TreeTable, I was giving the class object and the controller.

Thanks for your help.