0

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.

demongolem
  • 9,474
  • 36
  • 90
  • 105
SlimZ
  • 43
  • 1
  • 7
  • just to clarify, when you write 'two click' in your question are you referring to a toClick event? – coderwurst Feb 23 '17 at 13:34
  • yes two click event with the mouse :) – SlimZ Feb 23 '17 at 13:36
  • 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 Feb 23 '17 at 13:37
  • 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 Feb 23 '17 at 13:42
  • actually meant 'onClick' in my initial comment when I wrote 'toClick' event . Is this [SO question](http://stackoverflow.com/questions/11063273/gwt-celltable-selection-and-single-click-on-checkboxcell?rq=1) any help? – coderwurst Feb 23 '17 at 14:16
  • i tried with CellPreviewEvent bit it didn't work – SlimZ Feb 23 '17 at 16:26

2 Answers2

0

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

Adam
  • 5,403
  • 6
  • 31
  • 38
  • i tried with this but it didn't work when i click the first time it work but after when i click on another row i must do two click – SlimZ Feb 23 '17 at 16:29
  • @SlimZ, works for me. Do you get any error in browser console? Can you post minimal working example so we can debug it? – Adam Feb 24 '17 at 13:15
0

I did it with a 'SingleSelectionModel' and checkboxcell

  new CheckBoxCell(true, true)
SlimZ
  • 43
  • 1
  • 7