Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added some more description at the top in regards to the TreeGrid and how databinding works.

...

The TreeGrid component allows rendering of data that is structured with a parent/child relationship. With SmartGWT you can only assign one datasource to the TreeGrid, now this can cause a bit of a headache if the data is actually separated into multiple datasources. This is where the TreeGrid Facade Pattern comes in. The TreeGrid Facade Pattern means you create a custom datasource that sits infront of the underlying datasources and acts like a facade for the TreeGrid component.

In order to bind the data with the TreeGrid, it requires an id to make the nodes unique, a parent id in order to know where to render the node as well as a name field in order to display the node. The id's will be created by the facade by joining together the name of the datasource eg. teams and the id of the record, so for instance a team with id 3 would in the TreeGrid have an id of "teams:3". The parent id works very the same way except for the top level nodes where we leave it null. The name field we populate from what would be the most sensible field to represent the underlying data, this could even be a concatenation of several fields if need be.

As you can write a datasource both as a client side class and a server side class this article will give you a sample of both methods.

...

Now this is pretty straight forward, just like a normal datasource and we add a serverConstructor which is a fully qualified identifier for the server side class that implements this datasource. More information on custom datasource can be found at httpat http://www.smartclient.com/smartgwtee-latest/javadoc/com/smartgwt/client/docs/WriteCustomDataSource.html

It's important that we make sure the datasource has a primaryKey field, without this the datasource caching won't work.

...