ListGrid.setEditorCustomizer in SmartGWT [duplicat

2019-04-13 02:47发布

问题:

Possible Duplicate:
Smartgwt selectitem key value issue

I'm using setEditorCustomizer to set custom editors for some fields in a ListGrid, my specific problem is on a SelectItem

Something like this:

grid.setEditorCustomizer(new ListGridEditorCustomizer() {
    public FormItem getEditor(ListGridEditorContext context) {
         SelectItem selectItem = new SelectItem();
         LinkedHashMap<String, String> valuesMap = new LinkedHashMap<String, String>();
         valuesMap.put("0","some text");
         valuesMap.put("1","other text");
         selectItem.setValueMap(valuesMap);
    }
}

Note that I'm not creating select items for every row.

Everything works great when editing the row, I see "some text" and "other text" in the dropdown but when I'm not editing the value I see the corresponding key instead of the value.

I have searched the javadoc but couldn't find anything, if anything is not explicit please ask and I will add.

回答1:

You need to setValueMap() on the ListGridField where the SelectItem appears as well (with the same valueMap).



回答2:

Ended up finding a solution with a DataSource and setting it in the optionDataSource of the SelectItem and setting displayField and valueField to the respective fields.

And then for when the field is not being edited, in the ListGridField I set a custom CellFormatter that returned the proper data (this involves returning proper data for the other values too).

I'm pretty sure there may be a simpler way, but this way it works for me so I will leave it like that for now.