0
votes

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
just to clarify, when you write 'two click' in your question are you referring to a toClick event? - coderwurst
yes two click event with the mouse :) - SlimZ
ahh i think I we are talking about a double click? So when the user double clicks a row, you want to select the row and toggle a checkbox? - coderwurst
i can do it with double click but i must do it with just one click event when i select row the chackbox must change the state. - SlimZ
actually meant 'onClick' in my initial comment when I wrote 'toClick' event . Is this SO question any help? - coderwurst

2 Answers

0
votes

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
votes

I did it with a 'SingleSelectionModel' and checkboxcell

  new CheckBoxCell(true, true)