How to create a edit dialog for a datagrid in Jmix 2.0?

How to create a file(xml and java) for a edit dialog of a datagrid? Cause I wanna design the edit dialog so I wanna create a file(xml and java) for the edit dialog of a datagrid.

What do you mean by “edit dialog of a datagrid”?

If you want to create a view from scratch, use the “Blank view” template - it will create the XML descriptor and Java controller files. See an example in the tutorial: Creating UI from Scratch.

Cause I create an XML descriptor and Java controller files for the “edit” dialog to a datagrid. I will also create a “Edit” button to the edit dialog. From that, I can edit a row data from the datagrid in the “edit” dialog after selecting a row data from the datagrid and clicking the “Edit” button.

@Subscribe(“editBtn”)
public void onEditBtnClick(final ClickEvent event, FuelDetails2 fuelDetails2) {
FuelDetails2 selectedEntity = fuelDetails2sDataGrid.getSingleSelectedItem();
if (selectedEntity != null) {
// Open the custom edit dialog with the selected entity
openDetailViewToEditEntity(selectedEntity);
} else {
// Handle the case where no entity is selected
}
}

private void openDetailViewToEditEntity(FuelDetails2 fuelDetails2) {
    dialogWindows.detail(this, FuelDetails2ListViewEditDialog.class)
            .withViewClass(FuelDetails2ListViewEditDialog.class)
            .editEntity(fuelDetails2)
            .withAfterCloseListener(afterCloseEvent -> {
                if (afterCloseEvent.closedWith(StandardOutcome.SAVE)) {
                    // Handle the saved entity if needed
                }
            })
            .open();
}

IllegalStateException: Loader of edited entity container not found

You should define a loader for instance container used in FuelDetails2ListViewEditDialog.

For example:

<data>
    <instance id="departmentDc"
              class="com.company.onboarding.entity.Department">
        <fetchPlan extends="_base"/>
        <loader/> <!-- here it is --> 
    </instance>
</data>

It is used by the StandardDetailView base class to load the edited instance from the database.

1 Like

Thanks for help.