One to many and many to many relations

Hello. How can I make in DynamicForm relation field which allow editing many to many relations? From what I see in documentation I have to make my own Canvas based component which I can add to DynamicForm as CanvasItem with my own expected behaviour (two listgrids with drag and drop or one listgrid with “add”, “remove” buttons), am I right?

One to one and many to one I can do with SelectItem however I’m not able to setup custom display field.

		final SelectItem parentField=new SelectItem("parent");
		parentField.setOptionDataSource(PersonDataSource.getInstance2());
		parentField.setWidth(200);
		parentField.setPickListWidth(400);
		ListGridField categoryField=new ListGridField("category");
		ListGridField nameField=new ListGridField("itemName");
		ListGridField costField=new ListGridField("unitCost");
		ListGridField unitsField=new ListGridField("units");
		ListGridField inStockField=new ListGridField("inStock");
		ListGridField allKeys=new ListGridField("keys", "keys");
		allKeys.setType(ListGridFieldType.TEXT);
		allKeys.setCellFormatter(new CellFormatter() {
			public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
				return record.getAttributeAsString("itemName")+" ("+record.getAttributeAsString("unitCost")+" "+record.getAttributeAsString("units")+")";
			}
		});
		parentField.setPickListFieldsFields(nameField, costField, unitsField, inStockField, allKeys);
		parentField.setValueField("id");
		parentField.setDisplayField("keys");
		parentField.setStartRow(true);
		parentField.setEndRow(true);

I would like to show content of “keys” column as display value of drop down element. I also played little bit with Hint on SelectItem component however I’m not able to fetch selected row data from SelectItem element. Is it feasible for example in ChangeHandler of SelectItem component to get selected row of underlying ListGrid?

TNX

Pavel

There’s an API on SelectItem getSelectedRecord() that returns a ListGridRecord and is accessible via JSNI, soon to be added to SmartGWT.

On adding an interface for many-many relations: a CanvasItem is a good way to insert this right into the middle of a DynamicForm for layout purposes, but be aware, the grid is saving independently to it’s own DataSource. Putting it in a CanvasItem just inserts it’s into the form layout and doesn’t cause the grid to be automatically managed as related data.