Place all fields in a table in edit mode using a user selection

Hi, I have a table component, I want the fields of the table can be editable or not by pressing a checkbox that the user selects, I created a code that I see runs well but when I do not see the results, the table follows Without being able to edit, it may not be refreshing. How could I get it ?.
I am enclosing the code:

checkBox_EditarTodos.addValueChangeListener(e -> {
            //si marco el check dejo editar todos los campos
            if (Boolean.TRUE.equals(e.getValue())) {
                List<Table.Column> columnList = table_AnalisisDsecciones.getColumns();
                for (Table.Column c : columnList) {
                    c.setEditable(true);
                }  
                 table_AnalisisDsecciones.repaint();             
            } else {
                //simpre hay dos campos editables que son los de valor de inventario
                List<Table.Column> columnList = table_AnalisisDsecciones.getColumns();
                for (Table.Column c : columnList) {                   
                        c.setEditable(false);                    
                }
                table_AnalisisDsecciones.repaint();
            }
        });

Greetings.

1 Like

Hi,

The column’s editable attribute is applicable only if the corresponding table also has the editable=true attribute. Did you set the table to be editable?

Regards,
Gleb

Yes, the table is in edit mode.
Greetings.

Could you share your screen descriptor and controller code?

Regards,
Gleb

Hi Gleb, I attach the .xml of the screen and I put the controller, also attached an image of the screen to make it clearer, when clicking on the checkbox all the fields in the table have to be editable.

Controller:

package com.albertosancheznieto.soga.web.screens;

import com.haulmont.bali.util.ParamsMap;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.components.*;
import com.albertosancheznieto.soga.entity.AnalisisSecciones;
import com.haulmont.cuba.gui.data.GroupDatasource;

import javax.inject.Inject;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class Visualizaranalisissecciones extends AbstractWindow {

@Inject
private GroupTable<AnalisisSecciones> table_AnalisisDsecciones;
@Inject
private GroupDatasource<AnalisisSecciones, UUID> analisisSeccionesesDs;
@Inject
private CheckBox checkBox_EditarTodos;

@Override
public void init(Map<String, Object> params) {
    super.init(params);

    table_AnalisisDsecciones.setShowItemsCountForGroup(false);

    checkBox_EditarTodos.addValueChangeListener(e -> {
        //si marco el check dejo editar todos los campos
        if (Boolean.TRUE.equals(e.getValue())) {
            List<Table.Column> columnList = table_AnalisisDsecciones.getColumns();
            for (Table.Column c : columnList) {
                c.setEditable(true);
            }
            table_AnalisisDsecciones.repaint();
        } else {
            //simpre hay dos campos editables que son los de valor de inventario
            List<Table.Column> columnList = table_AnalisisDsecciones.getColumns();
            for (Table.Column c : columnList) {
                if (c.getId().toString().equals("inventarioInicial") || c.getId().toString().equals("inventarioFinal")) {
                    c.setEditable(true);
                } else {
                    c.setEditable(false);
                }
            }
            table_AnalisisDsecciones.repaint();
        }
    });

    table_AnalisisDsecciones.setClickListener("otrosGastos", new Table.CellClickListener() {
        @Override
        public void onClick(Entity item, String columnId) {
            openWindow("visualizarAnalisisAuxiliar", WindowManager.OpenType.DIALOG, ParamsMap.of("p_identificacionAnalisis", item.getValue("identificacionAnalisis"),
                    "p_jerarquia", item.getValue("jerarquia"), "p_concepto", "Otros Gastos"));
        }
    });

Greetings.

visualizarAnalisisSecciones.xml (9.0K)

Table-Edit-Fields

I found that editable attribute cannot be changed for columns during runtime. I’ve created an issue.
For now, I would recommend setting editable=“true” to all necessary columns declaratively and change Table’s editable attribute in runtime.
Regards,
Gleb

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-9386