Page 1 of 1

Master - Detail with empty Details

PostPosted: Tue Oct 30, 2018 11:23 am
by JuFi
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!

Re: Master - Detail with empty Details

PostPosted: Tue Oct 30, 2018 11:37 am
by rzenz
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.
    }
}

Re: Master - Detail with empty Details

PostPosted: Tue Oct 30, 2018 12:49 pm
by Support@SIB
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.