|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface TreeDataBinding
TreeGrid
component is a visual representation of a tree and
requires a Tree
or com.smartgwt.client..ResultTree
datatype passed via
the data
attribute to initialize the tree view. The Tree
datatype is used when you want to provide all of the tree nodes in one shot at
initialization time. The com.smartgwt.client..ResultTree
datatype is used when you want portions of the tree to
be loaded on demand from the server. Providing all data to the Tree at creation
The simplest
mechanism by which to initialize a Tree is to simply provide all the data up-front when the Tree itself is created.
Depending on the format of your tree data, this can be done by setting root
or data
. This
functionality is provided by the Tree
class.
For examples of this type of databinding, see the following SDK examples:
Loading Tree nodes on demand
In this mode, tree nodes are loaded on-demand the first time a
user expands a folder. This approach is necessary for large trees. This functionality is provided by the com.smartgwt.client..ResultTree
class.
ResultTrees require that every node in the tree have an 'id'
that is unique tree-wide. When the user expands a folder whose
contents have not yet been loaded from the server (or you programmatically call openFolder() on such a node), the client
automatically sends a DSRequest
to the server to ask for all immediate children of that
node. The DSRequest
criteria will specify the id of the node for which children are
being requested via the parentId
property (see parentIdField
). This client is asking the server: "give me all
nodes whose parentId is the id of this node".
If there are no pre-existing node ids in the dataset you are loading, you must generate node ids (because the client needs some way to identify nodes when talking to the server). Generally a node id should contain whatever information is required to fetch the node and it's children on the server. One typical approach is to use the path to the node as a node id. For XML datasets in particular, the path may be a valid XPath, so that server-side lookup of child nodes is just a matter of applying the node id as an XPath to a server-side XMLDocument.
com.smartgwt.client..ResultTree
s are created for you by the TreeGrid
when you set dataSource
, but you can pass an initial dataset to a databound TreeGrid by setting initialData
. The idField
is derived from the dataSource you provide to the TreeGrid -
the first field marked as primaryKey
:true becomes the
idField of the ResultTree. The parentIdField
is found by
looking for a field that has a foreignKey
property
pointing to the idField.
If you do not provide initialData
, the first DSRequest you receive will be a request for the nodes under root. The id of the root node of
the tree is the value of the rootValue
attribute on the parentIdField
of the Tree DataSource.
For examples of this type of databinding, see the following SDK examples:
Multi-Level load on demand
The ResultTree's DSRequests ask for the immediate children of a node only
(by specifying parentId
in the criteria). Any nodes returned whose parentId
field value is
unset or matches this criterion will be added to the tree as immediate children of the node. However you are also free
to return multiple levels of children. This can be done by simply returning a flat list of descendents with valid id's
and parentId's, exactly as though you were initializing a multi-level tree via data
.
Note that when receiving multiple levels of children, the ResultTree's assumption is that if any children are loaded for a parent, then that parent is considered fully loaded.
When loading children for a given parent node, the ResultTree calls DataSource.fetchData()
on its DataSource. For custom code that may need to reference the
parentNode or tree in some way, the parent node whose children are being loaded is available on the dsRequest instance
in the DataSource flow as dsRequest.parentNode, where it can be inspected during DataSource.transformRequest(com.smartgwt.client.data.DSRequest)
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |