开发者

How to use SmartGWT DataSource with heterogenous data

I want to use SmartGWT's TreeGrid object to show hierarchical data. The data is heterogeneous, not all elements are of the same type and have the same fields. For example, I have the following data:

Home
 |-Room 1
 |-Room 2
    |-Table
    |-Chair

All objects have unique IDs. Home has no fields. Rooms have just a name. Table has a name and an int field "seatsNumberOfPeople" which the Chair has not. Chair has a field "Color" taken from a list of possible values which the table has not.

When an object in the TreeGrid is selected, I want to show a DetailViewer which 开发者_Python百科lets the user edit the fields of that object. Obviously, the DetailViewer will have different fields and validations for each type of node.

How should the DataSource be designed to meet these requirements? What's the best practice to create such dynamic DetailViewer from that heterogeneous data?

Unfortunately, all examples on the web show data which is homogeneous (same fields for all objects in the Tree).


In this case, I would create a datasource that has two additional fields, external ID and external type. Let's presume you use the primary key as the external ID, and the datasource name as the type.

When you select a tree node, you then pass the ID and type to your detail viewer. It calls getDataSource(type) and fetch({criteria id = ID}) and then renders your detail. (of course that is psuedo code)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜