Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Listgrid dependent select icons change

    Hi All,
    I am referring to https://www.smartclient.com/smartgwt...endent_selects demo to create a dependent select listgrid.
    This works fine for values using setEditorValueMapFunction. So if I change value in field A, the corresponding values gets populated in field B.
    But my editor is selectitem with images in it. I tried setEditorValueIcons and setValueIcons but it works only for current loaded value. As soon as I change the value the icons never gets populated.

    Code:
     field.setEditorValueMapFunction(new EditorValueMapFunction() {
                            public Map getEditorValueMap(Map values, ListGridField field, ListGrid grid) {
                                Map<String, String> valueMap = new HashMap<String, String>();
                                Map<String, String> iconMap = new HashMap<String, String>();
                               String myValue = "someVal";
                                switch(myValue){
                                case "A" :
                                    valueMap.put("1","B");
                                    valueMap.put("2","C");
    
                                    iconMap.put("1","B");
                                    iconMap.put("2","C");
    
                                    break;
                                case "D":
                                    valueMap.put("5","E);
                                    iconMap.put("5","E");
    
                                    break;
                                    default:
                                        valueMap.put("6","F");
                                        iconMap.put("6","F");
                                }
    
                               /* departmentSelectItem.setValueIcons(iconMap);
                                field.setEditorValueIcons(iconMap);*/     Both of these are not working as expected
                                return valueMap;
                            }
                        });
    Do we have anything like setEditorValueIconFunction as well? I just want to update the dependent field's items with the images. So the valueicons of select item should also change. I am not able to find out. Kindly suggest.

    Thanks in advance.
    Last edited by preeti_kanyal; 3rd Apr 2019, 01:01.

    #2
    The easiest way to do this is to use your changed handler on the "division" field to explicitly update the valueIcons on the "department" item.
    You can get at the item via listGrid.getEditFormItem(<fieldName>)

    Your code would look something like this:
    Code:
            divisionSelectItem.addChangedHandler(new ChangedHandler() {  
                public void onChanged(ChangedEvent event) {  
                    FormItem departmentItem = localDataGrid.getEditFormItem("department");
                    departmentItem.setValueMap(getDepartmentValueMap((String)event.getValue()));
                    departmentItem.setValueIcons(getDepartmentValueIcons((String)event.getValue()));
                }  
            });
    This assumes you've got a 'getDepartmentValueIcons()' method which takes a value (the division field value) and returns a Map of valueIcon mappings.
    I've also made an assumption that you're taking a similar approach for the valueMap of the department field - doing this would get rid of the need for an editorValueMap function altogether.

    (We'll be considering internally whether it makes sense to add an editorValueIcons function as well, but if we do that wouldn't likely be backported to older branches)

    Regards
    Isomorphic Software

    Comment

    Working...
    X