GWT celltable combine two click in one

128 Views Asked by At

I have a celltable with checkbox. I want to combine two clicks; When I select the row, I also change the state of checkbox. I try the following, but it doesn't work:

column.setFieldUpdater(new FieldUpdater<Item, CheckBoxDisablingCell.CheckState>() {

  @Override
  public void update(int rowIndex, final Item item, final CheckBoxDisablingCell.CheckState state) {
    if(!state.isDisabled()) {                        

    item.getFonctions().get(index).setSelected(state.isChecked());

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

       @Override
       public void execute() {
           selectionModel.clear();
           selectionModel.setSelected(gestionHabilitationsItem, true);
           cellTableFonctions.setSelectionModel(selectionModel);
           leftCellTable.setSelectionModel(selectionModel);
         }
      });
    }
  }
});

With this code I have two click: one for select the row and another for change the state of the checkbox. How can I combine it? Appreciate any suggestions.

2

There are 2 best solutions below

2
Adam On

I think I got what you need by using:

  • SingleSelectionModel
  • CheckboxCell with handlesSelection set to false (default state)
  • Column that uses CheckboxCell and gets the value from SelectionModel

Example:

CheckboxCell checkboxCell = new CheckboxCell(); // handlesSelection = false
table.addColumn(new Column<TableType, Boolean>(checkboxCell) {
    @Override
    public Boolean getValue(TableType object) {
        return selectionModel.isSelected(object);
    }
});

Every time you select a row, checkbox is being automatically checked. Previously selected row is then deselected (and checkbox unchecked) as it is a single selection model.

enter image description here

0
SlimZ On

I did it with a 'SingleSelectionModel' and checkboxcell

  new CheckBoxCell(true, true)