问题
Need help regarding.selectall functionality. I have created a form.
DynamicForm form = new DynamicForm();
final SelectItem category = new SelectItem("category", "Employee Category");
category.setMultiple(true);
category.setValueMap("Direct","InDirect","ALL");
form.setFields(category);
If i select 'ALL' all three items in picklist should also be selected.if i deselect 'ALL' all three items should be deseleted. need help
回答1:
You can try out the following:
boolean isAllSelected = false; // global variable
SelectItem selectItem = new SelectItem("category", "Employee Category");
selectItem.setMultiple(true);
selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
selectItem.setValueMap("Direct","InDirect","ALL");
selectItem.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(ChangedEvent event) {
if (event.getValue() != null) {
if (event.getValue().toString().contains("ALL")) {
if (!isAllSelected) {
selectItem.setValues("Direct","InDirect", "ALL");
isAllSelected = true;
}
} else {
if (isAllSelected) {
selectItem.clearValue();
}
isAllSelected = false;
}
} else {
isAllSelected = false;
}
}
});
DynamicForm form = new DynamicForm();
form.setSize("800px", "400px");
form.setFields(selectItem);
form.draw();
来源:https://stackoverflow.com/questions/19831660/smartgwt-select-all-functionality