editorEnabled option for generated Column

I have one tab sheet on my screen and under one tab there is one data grid. I have generated a column for that data grid.

 DataGrid.Column networkIdColumn = networkRelationshipGrid.addGeneratedColumn("networkPublisherId", new DataGrid.ColumnGenerator<Status2, Object>() {
        @Override
        public Object getValue(DataGrid.ColumnGeneratorEvent<Status2> event) {
          //business logic
           return "";
        }

    @Override
    public Class<Object> getType() {
        return Object.class;
    }
}, 5);
networkIdColumn.setCaption("Publisher ID");
networkIdColumn.setEditable(true);

Now I want to enable inline editor for that generated column “networkPublisherId”. So by setEditable method I am trying to enable the inline editor but its not working. Following is the corresponding xml code for the same datagrid.

  <tab id="networkRelationshipTab"
                     caption="Network Relationships"
                     margin="true"
                     spacing="true">
                    <dataGrid id="networkRelationshipGrid"
                            datasource="statusNetworkDs"
                              height="100%"
                              editorEnabled="true"
                              width="100%" >
                        <columns>
                            <column property="mode" editable="true"/>
                            <column property="created" editable="false" />
                            <column property="value" editable="false"/>
                        </columns>
                    </dataGrid>
                </tab>

Please guide me with this.

Hi,

By default, a generated column can’t be edited because Inline Editor can’t infer a component to use as an editor field. In this case you need to define the EditFieldGenerator, e.g.:

@Inject
private DataGrid<Order> ordersDataGrid;
@Inject
private UiComponents uiComponents;

@Subscribe
protected void onInit(InitEvent event) {
    ordersDataGrid.getColumnNN("amount").setEditFieldGenerator(orderEditorFieldGenerationContext -> {
        LookupField<BigDecimal> lookupField = uiComponents.create(LookupField.NAME);
        lookupField.setValueSource((ValueSource<BigDecimal>) orderEditorFieldGenerationContext
                .getValueSourceProvider().getValueSource("amount"));
        lookupField.setOptionsList(Arrays.asList(BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN));

        return lookupField;
    });
}

Gleb

1 Like

Thankyou for your input!