How to set generated column position in table (Cuba creates it to be the last column)

Hello,

I created a generated column using this code

table.addGeneratedColumn("Declaration value", new Table.ColumnGenerator<Declaration>() {
        @Override
        public Component generateCell(Declaration entity) {
            Label field = (Label) componentsFactory.createComponent(Label.NAME);
             field.setValue(declaration.getValue());
            return field;
        }
    });

My table has 3 columns designed in Studio.
At runtime the table looks like this:
StudioColumn 1 | StudioColumn 2 | StudioColumn 3 | Generated column

How can I make the table look like this:
StudioColumn 1 | Generated column | StudioColumn 2 | StudioColumn 3 ?

Thanks,
Andrei

Hi Andrei,

addGeneratedColumn() method takes two parameters: identifier of the column and an implementation of the Table.ColumnGenerator interface. Identifier can match one of the identifiers set for table columns in XML-descriptor – in this case the new column is inserted instead of the one defined in XML. If the identifier does not match any of the columns, a new column is added to the right.

So, in your case the solution will be the following:

XML descriptor:

 <groupTable id="table"
     width="100%">
     <columns>
         <column id="studioColumn1"/>
         <column id="generatedColumn"/>
         <column id="studioColumn2"/>
         <column id="studioColumn3"/>
     </columns>
 </groupTable>

Screen controller:

table.addGeneratedColumn("generatedColumn", new Table.ColumnGenerator<Declaration>() {
        @Override
        public Component generateCell(Declaration entity) {
            Label field = (Label) componentsFactory.createComponent(Label.NAME);
            field.setValue(declaration.getValue());
            return field;
        }
    });
1 Like

Hi Olga,

Thank you very much, it worked.

Kind regards,
Andrei