Search code examples
javagwtgridcellgxt

Adding multiple buttons || cells in a cell in GXT 3.0 Grid


I'm using GXT 3.0 and I want to develop a grid table in it. In table, a cell assigned to be have multiple jobs, like save, delete, update. So I need to develop a grid table which has multiple buttons in a cell. To visualize the problem I'm sharing this image : enter image description here

I tried to add just a cell via

ColumnConfig.setCell() 

method, and It's succeeded. But I must add multiple buttons, or cells to handle events. In short form I need multiple Cells inside a Cell.

  • I know there is a method called ColumnConfig.setWidget(), but it didn't helped. It just added toolbar(or any widget element) to top(header part).
  • Remember that I use GXT 3.0

Thanks for any help.


Solution

  • You must use a CompositeCell :

    private CompositeCell<ObjectRow> createCompositeCell(){
    
    HasCell<ObjectRow, String> button1 = new HasCell<ObjectRow, String>() {
    
      public Cell<String> getCell() {
        return new ButtonCell();
      }
    
      public FieldUpdater<ObjectRow, String> getFieldUpdater() {
        return null;
      }
    
      public String getValue(ObjectRow object) {
        return "Button 1";
      }};
    
      HasCell<ObjectRow, String> button2 = new HasCell<ObjectRow,String>(){
    
        public Cell<String> getCell() {
          return new ButtonCell();
        }
    
        public FieldUpdater<ObjectRow, String> getFieldUpdater() {
          return null;
        }
    
        public String getValue(ObjectRow object) {
          return "Button 2";
        }
      };
    
      List<HasCell<ObjectRow, ?>> cells = new ArrayList<HasCell<ObjectRow, ?>>();
      cells.add(buton1);
      cells.add(button2);
    
      CompositeCell<ObjectRow> compositeCell = new CompositeCell<ObjectRow>(cells);
    
      return compositeCell;
    }
    

    You can set a different FieldUpdater for handle button click.