jQuery EasyUI Data Grid and Tree Plugin - Treegrid Tree Grid
jQuery EasyUI Plugins
Extends $.fn.datagrid.defaults. Override the default defaults via $.fn.treegrid.defaults.
The treegrid is used to display hierarchical data in a grid. It is based on the datagrid and combines a treeview with an editable grid. The treegrid allows you to create customizable, asynchronously expandable rows and display hierarchical data in multiple columns.
Depends on
- datagrid
Usage
Create a treegrid in HTML markup. In most cases, the treegrid follows the same structure and format as the datagrid.
Task Name
Persons
Begin Date
End Date
Create a treegrid using JavaScript.
$('#tt').treegrid({
url:'get_data.php',
idField:'id',
treeField:'name',
columns:[[
{title:'Task Name',field:'name',width:180},
{field:'persons',title:'Persons',width:60,align:'right'},
{field:'begin',title:'Begin Date',width:80},
{field:'end',title:'End Date',width:80}
]]
});
property
This property extends from the datagrid; the following are properties added for the treegrid.
| Name | Type | Description | Default value |
|---|---|---|---|
| idField | string | Defines the key field that identifies tree nodes. Required. | null |
| treeField | string | Defines the field of the tree node. Required. | null |
| animate | boolean | Defines whether to show animation when nodes are expanded or collapsed. | false |
| loader | function(param,success,error) | Defines how to load data from a remote server. Returning false cancels the action. This function has the following parameters: |
param:要传递到远程服务器的参数对象。
success(data):当检索数据成功时调用的回调函数。
error():当检索数据失败时调用的回调函数。 | json loader |
| loadFilter | function(data,parentId) | Returns the filtered data to display.| onSelect | event |
Events
This event extends from the datagrid; the following are events added for the treegrid.
| Name | Parameters | Description |
|---|---|---|
| onClickRow | row | Triggered when the user clicks a node. |
| onDblClickRow | row | Triggered when the user double-clicks a node. |
| onClickCell | field,row | Triggered when the user clicks a cell. |
| onDblClickCell | field,row | Triggered when the user double-clicks a cell. |
| onBeforeLoad | row, param | Triggered before the request to load data is sent; returning false cancels the load. |
| onLoadSuccess | row, data | Triggered when data is loaded successfully. |
| onLoadError | arguments | Triggered when data fails to load; the arguments parameter is the same as the 'error' method of jQuery.ajax. |
| onBeforeExpand | row | Triggered before a node is expanded; returning false cancels the expansion. |
| onExpand | row | Triggered when a node is expanded. |
| onBeforeCollapse | row | Triggered before a node is collapsed; returning false cancels the collapse. |
| onCollapse | row | Triggered when a node is collapsed. |
| onContextMenu | e, row | Triggered when a node is right-clicked. |
| onBeforeEdit | row | Triggered when the user starts editing a node. |
| onAfterEdit | row,changes | Triggered when the user finishes editing. |
| onCancelEdit | row | Triggered when the user cancels editing a node. |
Method
Many methods require a parameter named 'id', which represents the value of the tree node.
| Name | Parameters | Description |
|---|---|---|
| options | none | Returns the treegrid options. |
| resize | options | Sets the size of the treegrid; the options parameter contains two properties: |
width:树形网格(treegrid)的新宽度。
height:树形网格(treegrid)的新高度。 |
| fixRowHeight | id | Fixes the height of the specified row.| onSelect | event | loadData | data | Loads the treegrid data.| onSelect | event | load | param | Loads and displays the first page. Available since version 1.3.4.
Code example:
// load and send some request parameters
$('#tg').treegrid('load', {
q: 'abc',
name: 'name1'
});
| onSelect | event | reload | id | Reloads the treegrid data. If the 'id' parameter is passed, the specified row of the tree is reloaded; otherwise, all rows of the tree are reloaded.
Code example:
$('#tt').treegrid('reload', 2); // reload the row which value is equals to 2
$('#tt').treegrid('reload'); // reload the all rows
$('#tt').treegrid('reload', {id:2, q:'abc'}); // reload the specified row with 'q' parameter passing to server
| onSelect | event | reloadFooter | footer | Reloads the footer data.| onSelect | event | getData | none | Gets the loaded data.| onSelect | event | getFooterRows | none | Gets the footer data.| onSelect | event | getRoot | none | Gets the root node, returning a node object.| onSelect | event | getRoots | none | Gets the root nodes, returning an array of nodes.| onSelect | event | getParent | id | Gets the parent node.| onSelect | event | getChildren | id | Gets the child nodes.| onSelect | event | getSelected | none | Gets the selected node and returns it, or returns null if no node is selected.| onSelect | event | getSelections | none | Gets all selected nodes.| onSelect | event | getLevel | id | Gets the level of the specified node.| onSelect | event | find | id | Finds the specified node and returns its node data.| onSelect | event | select | id | Selects a node.| onSelect | event | unselect | id | Unselects a node.| onSelect | event | selectAll | none | Selects all nodes.| onSelect | event | unselectAll | none | Unselects all nodes.| onSelect | event | collapse | id | Collapses a node.| onSelect | event | expand | id | Expands a node.| onSelect | event | collapseAll | id | Collapses all nodes.| onSelect | event | expandAll | id | Expands all nodes.| onSelect | event | expandTo | id | Expands a specified node from the root.| onSelect | event | toggle | id | Toggles the expand/collapse state of a node.| onSelect | event | append | param | Appends some child nodes to a parent node; the 'param' parameter includes the following properties:
parent: the id of the parent node; if not assigned, the node is appended as a root node.
data: an array containing the node data.
代码实例:
// append some nodes to the selected row var node = $('#tt').treegrid('getSelected'); $('#tt').treegrid('append',{ parent: node.id, // the node has a 'id' value that defined through 'idField' property data: [{ id: '073', name: 'name73' }] });| onSelect | event | insert | param | Insert a node before or after the specified node. The 'param' parameter includes the following properties:
before: the id value of the node inserted before.
after: the id value of the node inserted after.
data: the new node data.
代码实例:
// insert a new node before the selected node var node = $('#tt').treegrid('getSelected'); if (node){ $('#tt').treegrid('insert', { before: node.id, data: { id: 38, name: 'name38' } }); } This method is available since version 1.3.1.| onSelect | event | remove | id | Remove a node and its children.| onSelect | event | pop | id | Pop a node and, after removing it, return the node data including its children. This method is available since version 1.3.1.| onSelect | event | refresh | id | Refresh the specified node.| onSelect | event | update | param | Update the specified node. The 'param' parameter includes the following properties:
id: the id of the node to update.
row: the new row data.
代码实例:
$('#tt').treegrid('update',{ id: 2, row: { name: 'new name', iconCls: 'icon-save' } }); This method is available since version 1.3.1.| onSelect | event | beginEdit | id | Begin editing a node.| onSelect | event | endEdit | id | End editing a node.| onSelect | event | cancelEdit | id | Cancel editing a node.| onSelect | event | getEditors | id | Get the editors of the specified row. Each editor has the following properties:
actions: the actions the editor can perform.
target: the jQuery object of the target editor.
field: the field name.
type: the editor type.| onSelect | event | getEditor | param | Get the specified editor. The param parameter contains two properties:
id: The id of the row node.
field: Field name. |
jQuery EasyUI Plugins