DataBound depends selects : ForeignKey paths ? naming convention

What is the naming convention for FK names

is the name of the FK significant ?

  parentField.setForeignKey("supplyCategoryDS.categoryName");
	DataSourceTextField itemNameField = new DataSourceTextField("categoryName", "Item", 128, true);  
         itemNameField.setPrimaryKey(true);  
   
         DataSourceTextField parentField = new DataSourceTextField("parentID", null);  
         parentField.setHidden(true);  
         parentField.setRequired(true);  
         parentField.setRootValue("root");  
         parentField.setForeignKey("supplyCategoryDS.categoryName");

The name of the FK field is not significant.

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.

Problems with foreignKey and ListGrid.fetchRelatedData

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

  1. 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).

  1. 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)

In summary, how to use DataSource.foreignKey?

Thanks for your help!

@khantran what you seem to be trying to do is just a databound ComboBox. You don’t need a foreignKey declaration. See the ComboBox samples.

I need auto-complete search feature of SelectItem so I don’t use ComboBox. Why i set foreignKey for DataSource but ListGrid can not re-use them?

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.