I am trying to create a CellTable that has a column with some text and a checkbox that will be used as the "Select All" checkbox (see the figure below, "cb" is the checkbox). I am currently using a class derived from the header and overriding its renderer method to display the text and checkbox. I override onBrowserEvent (), but it only gives me onChange events that will work fine, except that the checkbox is not working correctly. Anyone have any ideas on this?
+-------+------------+ | col 1 | Select All | | | cb | +-------+------------+ | row 1 | cb | +-------+------------+
The problem that I have with this checkbox is that when it is not checked, you need to double-click it on the checkmark (at least in Chrome), even if the "checked" property is true for the first time. One click canceled it correctly.
Here is the code:
Customizing CellTable columns:
private void setupTableColumns() {
My Select All Header:
public static class SelectAllHeader extends Header<Boolean> { private final String checkboxID = "selectAllCheckbox"; private ISelectAllHandler handler = null; @Override public void render(final Context context, final SafeHtmlBuilder sb) { String html = "<div>Select All<div><input type=\"checkbox\" id=\"" + checkboxID + "\"/>"; sb.appendHtmlConstant(html); } private final Boolean allSelected; public SelectAllHeader() { super(new CheckboxCell()); allSelected = false; } @Override public Boolean getValue() { Element checkboxElem = DOM.getElementById(checkboxID); return checkboxElem.getPropertyBoolean("checked"); } @Override public void onBrowserEvent(final Context context, final Element element, final NativeEvent event) { Event evt = Event.as(event); int eventType = evt.getTypeInt(); super.onBrowserEvent(context, element, event); switch (eventType) { case Event.ONCHANGE: handler.onSelectAllClicked(getValue()); event.preventDefault(); break; default: break; } } public void setSelectAllHandler(final ISelectAllHandler handler) { this.handler = handler; } }
source share