Advice for creating single editable table in v7.2?

Hello:

I am creating a CostHistory table in my database, containing:

id bigint,
fieldname varchar(30),
startdate date,
enddate date,
value numeric(10,2)

The idea is that we keep history of the cost values for various costs stored in the system. Each cost has a date range where it is effective. Consider this a poor man’s temporal table.

I am looking for the best way to put up a screen to maintain this. I don’t really want a Master/Detail editor. I prefer to edit in the table itself. It seems to be a cross between a StandardLookup and a StandardEditor. The current row in the table is the one I will edit. There will be an Add button to add new rows and a Delete button to delete rows (and fix the dates as necessary to keep things in sync).

There is no single entity to put as EntityToEdit for StandardEditor. On the other hand, StandardLookup is not designed to commit changes.

Is there a best practice to implement this in Cuba 7.2?

Hello!

If standard screens do not meet your demands you can create a simple screen (inheritor of Screen).

For inline editing fits good DataGrid with its inline editor. You can override default actions “create”, “edit” and use inline editor instead. See the example in the Sampler.

To save created or edited entity you can subscribe on EditorPostCommitEvent and commit entity using DataManager. For instance:

@Subscribe("dataGrid")
public void onDataGridEditorPostCommit(DataGrid.EditorPostCommitEvent event) {
    dataManager.commit(event.getItem());
}
1 Like

OK, thanks very much. I have written screens like this in the past. I was just wondering if there was a “supported” way to do it.

I tend to start with StandardLookup to get the base features, modify the table to editable=true, then capture the Create and Remove click events to do what I need.

This would be a great addition to your standard templates (hint, hint) :wink:

1 Like

It makes sense, thanks for suggestion.

1 Like