Search code examples
javagxt

How to add an image as a background for the cell in the GXT 2.2 Grid


I wanted to add the button to the cell but now I'm ready just to set an image for the background of the cell and than handle the click. how to add the image to the cell?


Solution

  • If you want to render a button in a column, see setRenderer method of ColumnConfig.

    The following will set a button on each row of the grid:

    ColumnConfig cfg = new ColumnConfig();
    cfg.setRenderer(new GridCellRenderer() {
        @Override
        public Object render(M model, String property,
                        ColumnData config, int rowIndex, int colIndex,
                        ListStore<M> store, Grid<M> grid) { 
            Button button = new Button();
            // set up button based on params to this render function
            // for example, the `model` argument is the item backing each row.
            // this render method is called for each row in the grid
            // see http://dev.sencha.com/deploy/gxt-2.2.5/docs/api/com/extjs/gxt/ui/client/widget/grid/GridCellRenderer.html
            return button;
        }
    }):