Search code examples
javabuttongridgxt

Adding button to the GXT Grid cell


I use GXT 2.2.0 and I need to make a button for deleting rows. It was an idea to make checkboxes and create a button "delete", but I already have checkbox for choosing rows by users to use them further and decided it is not "user-friendly". So how to add button to the cell?


Solution

  • to add the button to the cell I had to do this:

            column = new ColumnConfig();
            column.setRenderer(new GridCellRenderer() {
                @Override
                public Object render(ModelData model, String property, ColumnData config,                      int rowIndex, int colIndex, ListStore store, Grid grid) {
    
                    final int row = store.indexOf((PropertyItem) model);
    
                    Button b = new Button("remove", new SelectionListener<ButtonEvent>() {
                        @Override
                        public void componentSelected(ButtonEvent ce) {
                            Window.alert("row index= " + row);
                            remove(row, customerId);
                        }
                    });
    
                    b.setIconStyle("/gxt/images/gxt/icons/delete.png");
                    return b;
                }
            });