If the foreign DataSource is named “supplyCategory” the FK value should be just “supplyCategory.categoryName” - don’t tack on “DS” unless that’s actually the ID of the foreign DataSource.
I have read documents of ListGrid.fetchRelatedData and DataSourceField.foreignKey. But I cann’t understand meaning of them. I have two tables:
Ledger: id, code, description
AllocationVersion: id, ledgerId (FK), version, active
In AllocationVersion datasource, I set foreign as below:
DataSourceIntegerField ledgerField = new DataSourceIntegerField(
"ledger", "Ledger");
ledgerField.setRequired(true);
ledgerField.setForeignKey("ledgerDS.id");
I wonder how to ListGrid (which bound to AllocationVersionDS) know displayField use to display on column Ledger (i need display Ledger.description).
In AllocationVersionDS, if i set EditorType for DataSourceField, then I get error in DynamicForm bound to this datasource.
SelectItem ledgerItem = new SelectItem("ledger");
ledgerItem.setTitle("Ledger");
ledgerItem.setOptionDataSource(LedgerXmlDS.getInstance());
ledgerItem.setValueField("id");
ledgerItem.setDisplayField("description");
//ledgerField define on above
ledgerField.setEditorType(ledgerItem);
and then
factorForm = new DynamicForm(); factorForm.setDataSource(AllocationVersionXmlDS.getInstance());
//line 76
formLayout.addMember(factorForm);
there are errors
[ERROR] Unable to load module entry point class com.mycompany.client.HelloWorld (see associated exception for details)
com.google.gwt.core.client.JavaScriptException: (TypeError): Object expected
number: -2146823281
description: Object expected
at com.smartgwt.client.util.JSOHelper.setAttribute(Native Method)
at com.smartgwt.client.widgets.BaseWidget.getOrCreateJsObj(BaseWidget.java:280)
at com.smartgwt.client.widgets.layout.Layout.addMember(Layout.java:791)
at com.mycompany.client.HelloWorld.onModuleLoad(HelloWorld.java:76)
SelectItem also support optionDataSource. Not following what you mean about re-use - just be sure you actually look at the docs for optionDataSource. The property is available on both ListGrids and DynamicForms.