Announcement
Collapse
No announcement yet.
X
-
Hi Leochan,
try it like this here:
Note that this works only in 13.0d, and not 12.0p/12.1p, see this blog post.Code:roleData = [ { "id": 1, "role": "ADMIN" }, { "id": 2, "role": "USER" } ]; userData = [ { "id": 1, "username": "Bill", "role": "1" }, { "id": 2, "username": "lssss", "role": "2" } ]; isc.DataSource.create({ ID: "roleDataSource", fields:[ {name:"id", title:"ID", primaryKey: true}, {name:"role", title:"Role", required:true} ], clientOnly: true, testData: roleData }); isc.DataSource.create({ ID: "userDataSource", fields:[ {name:"id", title:"ID", width: 40, primaryKey:true}, {name:"username", title:"Username"}, {name:"role", title:"Rolename", foreignKey:"roleDataSource.id", [B]displayField: "roleName"[/B]}, [B]{name:"roleName", foreignKey:"roleDataSource.id", includeFrom:"roleDataSource.role"}[/B] ], clientOnly: true, testData: userData }); isc.ListGrid.create({ ID: "userAndRoleList", width:500, height:224, alternateRecordStyles:true, showAllRecords:true, dataSource: userDataSource, autoFetchData: true });
Best regards
Blama
Leave a comment:
-
Dear all,
So, for client-only DataSources, can I use foreign key for ManyToOne relation between two DataSources??
I want to display the roleDataSource.role in the column of userDataSource.role.
I tried as below but it does not work. Is there any way to solve this?
Sets of data:
DataSource created correspondingly:Code:roleData = [ { "id": 1, "role": "ADMIN" }, { "id": 2, "role": "USER" } ]; userData= [ { "id": 1, "username": "Bill", "role": "1" }, { "id": 2, "username": "lssss", "role": "2" }; ]
To display in a listGrid:Code:isc.DataSource.create({ ID: "roleDataSource", fields:[ {name:"id", title:"ID", primaryKey: true}, {name:"role", title:"Role", required:true} ], clientOnly: true, testData: roleData }) isc.DataSource.create({ ID: "userDataSource", fields:[ {name:"id", title:"ID", width: 40, primaryKey:true}, {name:"username", title:"Username"}, {name:"role", title:"Role", foreignKey:"roleDataSource.id", displayField: "roleDataSource.role"} ], clientOnly: true, testData: userData })
Thanks a lot!Code:isc.ListGrid.create({ ID: "userAndRoleList", width:500, height:224, alternateRecordStyles:true, showAllRecords:true, dataSource: userDataSource, autoFetchData: true })
Leo
Leave a comment:
-
Please revisit the docs for dataSourceField.includeFrom. We explain how to set up a displayField for this use case.
includeFrom is limited to server-side DataSources, as it’s a join, and there’s no efficient way to do that with eg two REST services. If you are not using our server DataSources, then you need to return the same data that would be returned by includeFrom.
Leave a comment:
-
I have the same problem while using ClientOnly-Datasources with cached data. For example I define a DataSourceField like this:
In my ListGrid is just displayed the id like "BP01000..."Code:DataSourceField field = new DataSourceField(); field.setForeignKey("Locations.id"); field.setForeignDisplayField("description");
When I edit the record row in my ListGrid, there's the correct description like "144.N":
and also in an edit form it is correct:
I found and read a lot about includeFrom etc. and tried to set it via attribute to another DataSourceField with two fields and so on, but that's not working.
Also I tried to setOptionsDataSource and setAutoFetchDisplayMap(true) to the ListGridField, but no...
Is the ForeignKeyDisplayField (and includeFrom) only working on database based DataSources or can I also use it on ClientOnly-Datasources and set it programmatically?Last edited by david.moers; 22 May 2019, 03:08.
Leave a comment:
-
works now
Found the answer in this thread: http://forums.smartclient.com/showthread.php?t=23289&highlight=includeFrom
Code:<DataSource ID="nutzerlogin" serverType="hibernate" schemaBean="de.bml.web.versandanzeige.server.model.NutzerLogin" autoDeriveSchema="true"> <fields> <field name="aktiv" hidden="true" /> <field name="passwortHash" hidden="true" /> <field name="kennung" /> <field name="nachname" /> <field name="vorname" /> <field includeFrom="rolle.bezeichnung" hidden="true" /> <field name="rolle" foreignKey="rolle.id" displayField="bezeichnung" editorType="SelectItem" /> <field name="idExtern" /> </fields> </DataSource>
Leave a comment:
-
same resultCode:<DataSource ID="nutzerlogin" serverType="hibernate" schemaBean="de.bml.web.versandanzeige.server.model.NutzerLogin" autoDeriveSchema="true"> <fields> <field name="aktiv" hidden="true" /> <field name="passwortHash" hidden="true" /> <field name="kennung" /> <field name="nachname" /> <field name="vorname" /> <field name="rolle" foreignKey="rolle.id" displayField="bezeichnung" includeFrom="rolle.bezeichnung" editorType="SelectItem" /> <field name="idExtern" /> </fields> </DataSource>
Not working either. Looks like it has no effect at all.Code:<DataSource ID="nutzerlogin" serverType="hibernate" schemaBean="de.bml.web.versandanzeige.server.model.NutzerLogin" autoDeriveSchema="true"> <fields> <field name="aktiv" hidden="true" /> <field name="passwortHash" hidden="true" /> <field name="kennung" /> <field name="nachname" /> <field name="vorname" /> <field name="rolle" foreignKey="rolle.id" includeFrom="rolle.bezeichnung" editorType="SelectItem" /> <field name="idExtern" /> </fields> </DataSource>
Btw, I'm using PRO, and "includeFrom" is not in the JavaDocs (it's referenced, but not documented). Is this intentional?
Leave a comment:
-
Datasource with foreign key works for DynamicForm,but not for ListGrid or DetailsView
version: v8.3p_2012-12-28/Pro Deployment (built 2012-12-28)
I use Hibernate-Beans and autoDerived Datasources. There are two classes with an One-To-Many relationship.
I use "foreignKey" to create the relationship, "displayField" to set the displayed field and editorType="SelectItem" to let the user choose between the instances of the referenced class (or rows of the corresponding table).
This works fine, when I use the datasource for a DynamicForm. The user can select the referenced instance, submit and the database is updated fine.
But it doesn't work for a ListGrid. The Column is blank and the DropDownList of the filter shows two empty cells.
Neither does it work for a details viewer, the field is empty.
So, how can I make it work with ListGrid and DetailsViewer too?
Datasources
Code:<DataSource ID="rolle" serverType="hibernate" schemaBean="de.bml.web.versandanzeige.server.model.Rolle" autoDeriveSchema="true"> <fields> <field name="aktiv" hidden="true" /> <field name="bezeichnung" /> </fields> </DataSource>
Code:<DataSource ID="nutzerlogin" serverType="hibernate" schemaBean="de.bml.web.versandanzeige.server.model.NutzerLogin" autoDeriveSchema="true"> <fields> <field name="aktiv" hidden="true" /> <field name="passwortHash" hidden="true" /> <field name="kennung" /> <field name="nachname" /> <field name="vorname" /> <field name="rolle" foreignKey="rolle.id" displayField="bezeichnung" editorType="SelectItem" /> <field name="idExtern" /> </fields> </DataSource>
Tags: None
Leave a comment: