automatic insertion of Row in the table during data entry

I have a master detail UI where I have a table column listener b which a new row is inserted when a new value is entered in the particular column. The code looks as follows:


 linesDs.addItemPropertyChangeListener(e -> {

            if ("quantity".equals(e.getProperty())) {
                linesTable.getRowsCount();
                ProductionGrLines line = metadata.create(ProductionGrLines.class);
                line.setProductionGr(productionGrDs.getItem());
                linesDs.addItem(line);
                linesDs.refresh();
                linesTable.setSelected(line);
                //showNotification("none", NotificationType.HUMANIZED);
                
            }
        });

I want to improve this functionality but seems like I need to know answer to the following questions:

  1. I want to insert the new row only at the end of the table (currently it is added randomly
  2. I can count the total number of Rows the table has. How can I get if the current row is the last row of the table. I want to insert a new row only when the user is editing a particular column of the last row. The new row should be created just below that.
  3. After a new row is created, the focus is lost, goes to URL or anywhere but i want the cursor moves to the new row created

If you want to insert the new row only at the end of the table please ensure that your lines property has type List, because Set is unordered. Also don’t call refresh on this datasource after adding item.

You can check if item is the last item of a datasource using method getItemIds:


import com.google.common.collect.Iterables;
...
usersDs.addItemPropertyChangeListener(e -> {
    if ("login".equals(e.getProperty())
            && Iterables.getLast(usersDs.getItemIds()) == e.getItem().getId()) {

        User user = metadata.create(User.class);

        usersDs.addItem(user);
        usersTable.setSelected(user);
        usersTable.requestFocus();
    }
});

For now it is not yet possible to move focus to concrete cell of a table, you can only request focus on the table itself:


usersTable.requestFocus();

We are planning to improve focus inside editable tables in the next minor release.

Thank you for your help and glad to know you are bringing that improvement in next minor release. I look forward for that.

Hi Yuriy
Any update on this enhancements that you wanted to include in the next minor release?

Hi,

The issue is not scheduled for any release yet, but we will try to provide a fix in the next minor release, that we plan to roll out (September 2016).

Thank you

I’m interested in this feature, to set focus on specific cell of new line added.

Please, when it’s available, post a litlle example.

Thanks!

Hi.

An ability to put focus on the required cell is added in the platform version 6.3.0.

Call the “void requestFocus(E entity, String columnId)” method for the target table.


myTable.requestFocus(entity, "name");