Inline order with details

Hi, can you provide an example of simple Screen for Order / Invoice with button Add, that adds directly to TableGrid a new line for edit? (we are searching to don’t open a product browser to add this line).

Details Order with TableGrid with lines.

Hi Ivan,

If you want to create such a table with in line adding and editing you have to add table:


<table id="linesTable"
       width="100%"
       editable="true">
    <actions>
        <action id="add"
                caption="mainMsg://actions.Add"
                icon="icons/create.png"
                invoke="addOrderLine"/>
        <action id="remove"
                caption="mainMsg://actions.Remove"
                icon="icons/remove.png"
                invoke="removeOrderLine"
                trackSelection="true"/>
    </actions>
    <columns>
        <column id="product" editable="true" optionsDatasource="productsDs"/>
        <column id="count" editable="true"/>
    </columns>
    <rows datasource="linesDs"/>
    <buttonsPanel>
        <button action="linesTable.add"/>
        <button action="linesTable.remove"/>
    </buttonsPanel>
</table>

In this table I set editable for columns and editable for whole Table, also I use optionsDatasource attribute for column with in line dropdown.

Controller of this screen will contain two methods for adding and removing lines of an order:


public class OrderEdit extends AbstractEditor<Order> {
    @Inject
    private CollectionDatasource<OrderLine, UUID> linesDs;
    @Inject
    private Metadata metadata;

    public void addOrderLine() {
        OrderLine orderLine = metadata.create(OrderLine.class);
        orderLine.setOrder(getItem());
        linesDs.addItem(orderLine);
    }

    public void removeOrderLine() {
        if (linesDs.getItem() != null) {
            linesDs.removeItem(linesDs.getItem());
        }
    }
}

I’ve attached my sample project so you can try it in action.

editable-table-inline

editable-order.zip (25.7K)

Perfect!!

the line i’m searching is:


linesDs.addItem(orderLine);

After add this in my code, works perfectly!!

And it’s possible, to put a field on the top of the table, with a selector of product, and button to add their line in grid?

Can you modify your example with anything similar?

You can do this yourself by using LookupField component with optionsDatasource and ValueChangeListener for this field with actual adding logic.

And then if you have a question about how to use LookupField or listeners or something else you can ask me.

i’ve added pickerfield, but we like to in same button of addline, if exists selected product in component, adds directly.

How can i detect if exist any selected product in lookupfield?

Thanks!

You can use getValue() method to obtain value of LookupField/PickerField/etc, so if value == null then there is no selected value in a field.

Perfect, i Share the code:


package com.company.imgestion.gui.presupuestos;

import com.haulmont.chile.core.common.ValueListener;
import com.haulmont.cuba.core.global.DataManager;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.gui.components.AbstractEditor;
import com.company.imgestion.entity.Presupuestos;
import com.company.imgestion.entity.PresupuestosLineas;
import com.haulmont.cuba.gui.components.LookupPickerField;
import com.haulmont.cuba.gui.components.actions.EditAction;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.data.Datasource;

import javax.inject.Inject;
import javax.inject.Named;
import java.math.BigDecimal;
import java.util.Map;
import java.util.UUID;
import com.haulmont.cuba.gui.components.Component;

public class PresupuestosEdit extends AbstractEditor<Presupuestos> {
  @Inject
    private LookupPickerField selectorarticulo;
}

public void addlinedirectly(Component source) {
       BigDecimal cero = BigDecimal.ZERO;

       PresupuestosLineas lineas = metadata.create(PresupuestosLineas.class);
       lineas.setDescripcion("");
       if ((selectorarticulo.getValue()) != null){
           lineas.setArticulo(selectorarticulo.getValue());
       }
       lineas.setCabecera(getItem());
       lineasDs.addItem(lineas);
       selectorarticulo.setValue(null);
    }

Now, i cannot getItem from the LookupPickerField no?

I would like to set the description, the description of product:

lineas.setDescripcion(selectorarticulo.getValue().getItem().GetDescrtipcion();

in Black, not exists…
It’s not valid LookupField to work as an Object?

You’ve just set value of field to null:


selectorarticulo.setValue(null);

So getValue() will return null, and if you want to use value to set description of order line you have to do it before setting null value to LookupPickerField selectorarticul.

Yes, iset to null after insert line, it’s good.

But before, i cannot navigate tot the object to get Description. Or maybe i need to set a new variable and setValue () and then work with this object?

I recommend to get value of field to a separate value of type Product and then to work with that typed variable.