Search code examples
gwtextjsgxt

GXT EditorGrid: choose cell editor type on a cell by cell basis


GXT EditorGrid provide a mechanism to set a type of editor for a column.

Is there anyway to define the editor type on a cell by cell basis?

For the curious minds:

I need to create a transposed table; the column become the row and the row is the column. That being the case, a column (from a normal table point of view) will have various editor type, whereby a row will have identical editor type.


Solution

  • basically, you have to handle the BeforeEdit event and set the editor. Here is a base class from which you can implement your grid:

    public abstract class AnyEditorGrid<T extends ModelData> extends EditorGrid<T> {
    
        public AnyEditorGrid(final ListStore<T> listStore, final ColumnModel columnModel) {
            super(listStore, columnModel);
            addListener(Events.BeforeEdit, new Listener<GridEvent<T>>() {
                @Override
                public void handleEvent(final GridEvent<T> be) {
                    final CellEditor editor = getEditor(be.getRowIndex(), be.getColIndex(), be.getModel());
                    if (editor != null) {
                        getColumnModel().setEditor(be.getColIndex(), editor);
                    } else {
                        be.setCancelled(true);
                    }
                }
            });
        }
    
        protected abstract CellEditor getEditor(int rowIndex, int colIndex, T model);
    
    }