MultiselectionModel

182 views
Skip to first unread message

Thomas Frisch

unread,
Nov 13, 2012, 3:41:02 AM11/13/12
to google-we...@googlegroups.com
Hi,
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:

MultiselectionModel<Object> msm = new MultiSelectionModel<Object>();
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);


With kinda works I mean the following:
- 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)


Please can anyone help me??


Thomas Broyer

unread,
Nov 13, 2012, 3:45:58 AM11/13/12
to google-we...@googlegroups.com
See https://code.google.com/p/google-web-toolkit/issues/detail?id=7014#c6
You have to use "new CheckboxCell(true, false)".

Thomas Frisch

unread,
Nov 13, 2012, 4:00:31 AM11/13/12
to google-we...@googlegroups.com
I added the selectAllBox with new CheckboxCell(true, false)
and it worked but still when I add this Checkbox as footer it does not work?
Reply all
Reply to author
Forward
0 new messages