I have a cell table with a column that contains a checkbox. Now I would like to add a 'select all box' that when selected all other checkboxes in the cell table are selected. I tried to use a MultiselectionModel for that. When I add the select all check box as a footer it does not work at all only when I add it as the header widget it 'kinda' works. Here is how I use it:
table.setSelectionModel(msm, DefaultSelectionEventManager.<Object> createCheckboxManager());
Header<Boolean> selectAllHeader = new Header<Boolean>(new CheckboxCell()) {
@Override
public Boolean getValue() {
return msm.getSelectedSet().size() == table.getRowCount();
}
};
selectAllHeader.setUpdater(new ValueUpdater<Boolean>() {
@Override
public void update(Boolean value) {
for (Object msg : table.getVisibleItems()) {
msm.setSelected(msg, value);
}
}
});
Column<Object, Boolean> select = new Column<Object, Boolean>(new CheckboxCell()) {
@Override
public Boolean getValue(Object object) {
return msm.isSelected(object);
}
};
select.setFieldUpdater(new FieldUpdater<Object, Boolean>() {
public void update(int index, Object object, Boolean value) {
msm.setSelected(object, value);
}
});
Header<String> colHeader = new Header<String>(new TextCell()) {
@Override
public String getValue() {
return "HEADER";
}
};
//when adding like this does select all does not work
table.addColumn(select, colHeader, selectAllHeader);
//when adding the select all check box as header it 'kinda' works
table.addColumn(select, selectAllHeader);
- Click on Check-all box -> everything is selected but check-all box is not selected (NOT OK)
- Click on check-all box again -> everything still selected and now also check-all box selected (OK)
- Click on check-all box again -> nothing is selected but check-all box is still selected (NOT OK)
- Click on check-all box again -> nothing is selected and now also check-all box is not selected (OK)