Treegrids

To enable this feature, ensure grid.treegrid.js is loaded. For more information refer to Installation

Treegrid supports both the Nested Set model and the Adjacency model. Good articles describing the Nested Set model can be found here:

Configuration options

This feature uses the following properties and methods of the basic grid.

Properties

Property Type Description Default
ExpandColClick boolean when true, the tree is expanded and/or collapsed when we click on the text of the expanded column, not only on the image true'
treeGrid boolean Enables (disables) tree grid. When this option is set to true, the following features are disabled:
  • subGrid
  • multiselect
  • pager elements -- buttons, etc. -- (but not the pager itself)
  • altRows
true
treeModel string 'nested' or 'adjacency' 'nested'
treeReader array extends the colModel defined in the basic grid. The fields described here are added to end of the colModel array and are hidden. This means that the data returned from the server should have values for these fields. For a full description of all valid values see treeReader properties. empty array


Methods

Method Parameters Description
collapseNode record Collapse the node at specified record
collapseRow record Collapse the current row
delTreeNode rowid Where rowid is the id of the row. Deletes the specified node and all child nodes of that node
expandNode record Expand the node at the specified record
expandRow record Expand the current row
getInd object, rowid, rc where object is the current set of grid rows (returned from jQuery("grid_id).rows); rowid is the id of the row; and rc should be set to true
getNodeAncestors record returns the ancestors of the specified record
getNodeDepth record returns the depth of the specified record
getNodeParent record Returns the parent node of the specified record
getNodeChildren record Returns the child nodes of the specified record; returns empty array if none
getRootNodes none Returns an array of the current root nodes
isNodeLoaded record Returns true if the node is already loaded
isVisibleNode record Returns true or false if the node is visible or not
setTreeRow rowid, data this method is just like setRowData, but can be used when treeGrid is enabled. When we use tree grid we should use setTreeRow instead of setRowData (this will be improved in the future releases - autodetecting the mode and use only one method - setRowData)
SortTree direction Direction is 'asc' or 'desc'; sorts the tree with the currently set sortname (sortname is from grid option)

In the methods above, record means the current record, which can be obtained via the getInd method


Cautions/Limitations

  1. Currently adding nodes with addRowData is not supported.
  2. Currently it is not recommended to combine inline editing and form editing with treegrid, or the expanded column will not be editable.
  3. Adding nodes is currently not suported.
  4. When we initialize the grid and the data is read, the datatype is automatically set to local. This is required because treegrid supports autoloading tree nodes. This means that, for speed or efficiency, you can load the data only for the root level first and load the data for a particular child node only when the operator clicks to expand that node. The grid will determine that there is no data and try to load the node from the server, but in this case the data that is sent to the server has to have additional parameters. Setting datatype to local permits intervening before the request is made to buidl the request correctly.
    In this case, postData array would like this:
    postData:{nodeid:rc.id,n_left:rc.lft,n_right:rc.rgt,n_level:rc.level}

    In other words you can grab these values and do something like this to load the child nodes.
    SELECT category_name, level, lft, rgt FROM categories WHERE lft > n_left AND rgt < n_right AND level = n_level +1 ORDER BY lft;

    Once all the nodes are loaded we do not make any other request to the server


Known bugs

  1. In FF2 and IE when trying to resize the expandable column the tree images are shown - i.e - wrapping does not resize.


Planned additions

  1. expandAll and collapseAll methods
  2. autoclosing tree nodes - when clicking on a node all other nodes at this level should be collapsed automatically and only the one clicked will be expanded
  3. addNode method



  Last Updated: 3/1/2009 | © Tony's jqGrid - a jQuery Plugin, 2010