SmartClient Version: SC_SNAPSHOT-2011-12-05/LGPL Development Only (built 2011-12-05)
Chrome 34
SmartGWT 3.0
I have a Select All checkbox on top of ListGrid.
Initially there is no group by applied on the ListGrid.
So when the Select All checkbox is checked all the records are selected.
Now I group by "name" field.
There are two groups GROUP1 & GROUP2
When I try to uncheck the Select All checkbox ,the records in the groups are not unchecked.(still they are in checked state)
Following is code.
Chrome 34
SmartGWT 3.0
I have a Select All checkbox on top of ListGrid.
Initially there is no group by applied on the ListGrid.
So when the Select All checkbox is checked all the records are selected.
Now I group by "name" field.
There are two groups GROUP1 & GROUP2
When I try to uncheck the Select All checkbox ,the records in the groups are not unchecked.(still they are in checked state)
Following is code.
Code:
public class ListGridGroupBy implements EntryPoint {
CheckboxItem selectAllCheckBoxItem;
ListGrid grid;
@Override
public void onModuleLoad() {
grid = new ListGrid();
grid.setWidth(300);
ListGridField checkBoxField = new ListGridField("checkBox", " ");
checkBoxField.setWidth("4%");
checkBoxField.setAlign(Alignment.LEFT);
checkBoxField.setType(ListGridFieldType.BOOLEAN);
checkBoxField.setCanFilter(false);
checkBoxField.setCanEdit(true);
checkBoxField.setCanToggle(true);
checkBoxField.setDefaultValue(Boolean.FALSE);
grid.setFields(checkBoxField, new ListGridField("id", "ID"),
new ListGridField("name", "Name"));
grid.setData(createData());
grid.setHeight(400);
grid.addGroupByHandler(new GroupByHandler() {
@Override
public void onGroupBy(GroupByEvent event) {}
});
VLayout vlayout = new VLayout();
vlayout.addMember(createSelectAllForm());
vlayout.addMember(grid);
vlayout.draw();
}
private ListGridRecord[] createData() {
ListGridRecord[] records = new ListGridRecord[10];
for (int i = 0; i < 10; i++) {
records[i] = new ListGridRecord();
records[i].setAttribute("id", i);
records[i].setAttribute("name", i % 2 == 0 ? "GROUP1" : "GROUP2");
}
return records;
}
private DynamicForm createSelectAllForm() {
DynamicForm df = new DynamicForm();
df.setMargin(0);
selectAllCheckBoxItem = new CheckboxItem("selectAll", "Select All");
selectAllCheckBoxItem.setShowTitle(false);
selectAllCheckBoxItem.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(final ChangedEvent event) {
if (grid.isGrouped()) {
if (grid.getGroupTree() != null
&& grid.getGroupTree().getAllNodes() != null) {
final TreeNode[] nodes = grid.getGroupTree()
.getAllNodes();
Tree tree = grid.getGroupTree();
for (int i = 0; i < nodes.length; i++) {
if (nodes[i] != null && !tree.isFolder(nodes[i])) {
GWT.log("Logging to check if the changes are taken");
final TreeNode temp = nodes[i];
temp.setAttribute(
"checkBox",
event.getValue() instanceof Boolean ? (Boolean) event
.getValue() : false);
if ((Boolean) event.getValue()) {
grid.selectRecord(i);
} else {
grid.deselectRecord(i);
}
grid.refreshRow(i);
}
}
}
} else if (grid.getRecords() != null
&& grid.getRecords().length > 0) {
for (int i = 0; i < grid.getRecords().length; i++) {
boolean select = event.getValue() != null ? (Boolean) event
.getValue() : false;
if (select) {
grid.selectRecord(i);
} else {
grid.deselectRecord(i);
}
grid.setEditValue(i, 0, select);
grid.refreshRow(i);
}
}
}
});
df.setFields(selectAllCheckBoxItem);
return df;
}
}
Comment