I’ve got ListGrid populated with editable data and one field is a choice from number of options. List of options depends on record, therefore I cannot just set valueMap property on DataSourceField and use standard editor. Could you tell me about possible solutions?
When I tried to change valueMap in corresponding ListGridField on editorEnter event actual option list was not changed. And BTW when you start record editing editorEnter event generated only for field you clicked on. Approach with changing valueMap on recordClick event works but it is even more far from perfectness:)
Ok, didn’t figure out that editorValueMap should be used…
By my question “Are there any plans to add something to SmartGWT (better say to SmartClient) to support such per record customization of possible field values?” I meant support of this also on DataSource level, something like valueMap could be read from ListGridRecord (for particular field) - actual list of possible values usually is “model” part. Of course, support of valueMap on “view” level (ListGrid/ListGridField) still useful since it provides developer with freedom of choice use MVC or not.
I’ve got a problem to use combobox (or select box) as editor. Code:
private static final EditorEnterHandler EDITOR_ENTER_HANDLER = new EditorEnterHandler() {
public void onEditorEnter(EditorEnterEvent event) {
int rowNo = event.getRowNum();
int colNo = event.getColNum();
setListGridEditorValueMap(event.getGrid(), colNo, (rowNo + 1) + "x"
+ (colNo + 1), rowNo + "/" + colNo);
};
};
private static final EditorExitHandler EDITOR_EXIT_HANDLER = new EditorExitHandler() {
public void onEditorExit(EditorExitEvent event) {
setListGridEditorValueMap(event.getGrid(), event.getColNum(),
(String[]) null);
}
};
private static native void setListGridEditorValueMap(ListGrid grid,
int colNo, String... valueMap) /*-{
var _grid = grid.@com.smartgwt.client.widgets.grid.ListGrid::getJsObj()();
var _valueMap = @com.smartgwt.client.util.JSOHelper::convertToJavaScriptArray([Ljava/lang/Object;)(valueMap);
_grid.setEditorValueMap(colNo, _valueMap);
}-*/;
...
// ListGridField setup
...
gridField.setEditorType(new ComboBoxItem());
gridField.addEditorEnterHandler(EDITOR_ENTER_HANDLER);
gridField.addEditorExitHandler(EDITOR_EXIT_HANDLER);
...
It works but only on first field I clicked to edit. When I click then another field in edit row “enter” event is not fired at all. And I cannot complete edit by ENTER or cancel it by ESC (like in case of text field as editor by default). What’s wrong with my code?
Thank you.
LATER:
Never mind, I didn’t check that JSOHelper.convertToJavaScriptArray doesn’t work with null as parameter. So,
var _valueMap = valueMap
? @com.smartgwt.client.util.JSOHelper::convertToJavaScriptArray([Ljava/lang/Object;)(valueMap)
: null;
in my native method solved the problem.
BTW: in SmartGWT DataSourceField.setValueMap(String…) or ListGridField.setValueMap(String…) also should suffer from this problem since JSOHelper.setAttribute works that way. IMHO it is minor bug while null (not empty array) mentioned as default value.