Table of Contents

TreeGrid

Treegrid is a way to represent hierarchical data in grid.
Treegrid supports both the Nested Set model and the Adjacency model. Good articles describing the Nested Set model can be found here:

http://ftp.ntu.edu.tw/MySQL/tech-resources/articles/hierarchical-data.html
http://www.sitepoint.com/article/hierarchical-data-database .

Installation

In order to use this module you should mark the Treegrid when you download the grid. For more information refer to Download.
For Developers - this is the grid.treegrid.js in the src directory.

Before you begin with the tree grid, it is highly recommended to read the articles listed above or any other related to hierarchical data representation articles.

Options

The following options can be set in the grid options to configure the treeGrid

OptionTypeDescriptionDefault
ExpandColClickbooleanwhen true, the tree is expanded and/or collapsed when we click on the text of the expanded column, not only on the imagetrue
ExpandColumnstringindicates which column (name from colModel) should be used to expand the tree grid. If not set the first one is used. Valid only when treeGrid option is set to true.null
treedatatypemixedDetermines the initial datatype (see datatype option). Usually this should not be changed. During the reading process this option is equal to the datatype option.null
treeGridbooleanEnables (disables) the tree grid format.false
treeGridModelstringDeteremines the method used for the treeGrid. Can be nested or adjacency.nested
treeIconsarrayThis array set the icons used in the tree. The icons should be a valid names from UI theme roller images. The default values are: {plus:'ui-icon-triangle-1-e',minus:'ui-icon-triangle-1-s',leaf:'ui-icon-radio-off'}
treeReaderarrayextends 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 below.
tree_root_levelnumericDetermines the level where the root element begins when treeGrid is enabled0
If the gridview option in the grid is set to true the treeGrid will not be constructed instead that set to true.

The treeReader property adds dynamically columns to the colModel property of the basic grid when treeGrid property is set to true. Syntax:

treeReader : {
   property1 : value1
   ...
   propertyN : valueN
}

The treeReader property is adds diffrent columns in the colModel depending on the treeGridModel property - i.e. we have diffrent configurations for different models - Nested Set Model and Adjacency Model.

Currently jqGrid can work only with data returned from server. There are some tricks and articles wich describes how to work with local data.

It is important to note here that the data returned from the server should be sorted in an appropriate way; for example
SELECT category_name, level, lft, rgt FROM categories ORDER BY lft;

 Tree Grid

Methods

In the methods below, record means the current record, which can be obtained via the getInd method like this:

var record = jQuery("#grid_id").getInd(rowid,true);

NOTE: This no longer works as of version 3.7.x. Use var record = jQuery(“#grid_id”).getRowData(rowid); instead.

Where rowid is the id of the row. Note the second parameter in the method. If the second parameter is omited or set to false (default) the returned value is the index of the row. If the row can not be found a false is returned.

MethodParametersDescription
addChildNode nodeid, parentid, data Add a node in the tree according the value of the parentid parameter. The nodeid is the unique values in the row. If set to empty string the method gets the next max number + 1 from the data. if parendid is null the node is added as root. If the parentid is valid id of existing row the data is added as child of the that row. Data is a data to be inserted.
collapseNoderecordCollapse the node at specified record
collapseRowrecordCollapse the current row
delTreeNoderowidWhere rowid is the id of the row. Deletes the specified node and all child nodes of that node. Does not delete the node at server
expandNoderecordExpand the node at the specified record
expandRowrecordExpand the current row
getNodeAncestorsrecordreturns array of the ancestors of the specified record
getNodeDepthrecordreturns the depth of the specified record
getNodeParentrecordReturns the parent node of the specified record
getNodeChildrenrecordReturns array of child nodes of the specified record; returns empty array if none
getRootNodesnoneReturns an array of the current root nodes.
isNodeLoadedrecordReturns true if the node is already loaded
isVisibleNoderecordReturns true or false if the node is visible or not
setTreeRowrowid, data The same as setRowData
SortTreedirectionDirection is 1 (meaning ascending) or -1 (meaning descending); sorts the tree with the currently set sortname (sortname is from grid option)

Cautions and Limitations