Smartgwt SELECT ALL functionality

2019-09-12 12:27发布

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

标签: gwt smartgwt
1条回答
在下西门庆
2楼-- · 2019-09-12 13:01

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();
查看更多
登录 后发表回答