Master - Detail with empty Details
3 posts
• Page 1 of 1
Master - Detail with empty Details
Hi,
I have a table which I use as a master and the corresponding details are in an other table. I have connected those two via the setMasterReference function and this is working perfectly.
My problem is that not every row in my master has a corresponding detail row. In this case the detail editors become disabled/not editable.
How can I make those editors editable and also save the user input into a new row in the details table.
Thank you in advance!
I have a table which I use as a master and the corresponding details are in an other table. I have connected those two via the setMasterReference function and this is working perfectly.
My problem is that not every row in my master has a corresponding detail row. In this case the detail editors become disabled/not editable.
How can I make those editors editable and also save the user input into a new row in the details table.
Thank you in advance!
- JuFi
- Posts: 12
- Joined: Thu Oct 11, 2018 2:20 pm
Re: Master - Detail with empty Details
If there is no row in the DataBook you can only add a new one, there is no "new row by default" mechanic in JVx. So what you must do is listen to selection changes on the master and change the detail accordingly. Without doing much testing, something like this:
- Code: Select all
masterDataBook.eventBeforeRowSelected().addListener(this::doProcessNewDetailRow);
masterDataBook.eventAfterRowSelected().addListener(this::doAddDetailRowIfNeeded);
// Later in the same class.
private void doAddDetailRowIfNeeded(DataBookEvent pDataBookEvent) throws ModelException
{
if (detailDataBook.getRowCount() == 0)
{
detailDataBook.insert(false);
}
}
private void doProcessNewDetailRow(DataBookEvent pDataBookEvent) throws ModelException
{
if (detailDataBook.getRowCount() == 1 && detailDataBook.isInserting())
{
// Save or revert here.
}
}
-
rzenz - Posts: 36
- Joined: Mon Dec 12, 2016 1:40 pm
- Location: Vienna, Austria
Re: Master - Detail with empty Details
Is it a big problem for the user to insert a new record, e.g. press a "New record" button or is it a complex use-case?
Otherwise, the given example would help to implement your requirement. Every UIEditor needs a bound datarow/databook otherwise it's disabled. Sure, it's possible to use simple UITextEditor and sync the values manually, but this isn't recommended and needs more code and work.
Otherwise, the given example would help to implement your requirement. Every UIEditor needs a bound datarow/databook otherwise it's disabled. Sure, it's possible to use simple UITextEditor and sync the values manually, but this isn't recommended and needs more code and work.
-
Support@SIB - Posts: 355
- Joined: Mon Sep 28, 2009 1:56 pm
3 posts
• Page 1 of 1