jQuery.treetable使用及异步加载
Usage
1 GitHub 地址 https://github.com/ludo/jquery-treetable/
2 API 地址 http://ludo.cubicphuse.nl/jquery-treetable/
3 jQuery 官网链接 http://plugins.jquery.com/treetable/
引入代码:
<link href="path/to/jquery.treetable.css" rel="stylesheet" type="text/css" /> <script src="path/to/jquery.treetable.js"></script> <script> $("#your_table_id").treetable(); </script>
注意事项:
1 在表格中展示树,每个tr 须拥有 data-tt-id 属性,且属性值必须唯一
When you pasted the above code and adjusted it to reflect your situation, you enabled the possibility of displaying a tree in your table. To make the tree actually display as a tree you have to add data-tt-id and data-tt-parent-id attributes to your table rows (tr).
2 每个子节点必须有一个 data-tt-parent-id 属性,data-tt-parent-id 的值必须等于 父节点的data-tt-id 值
3 表格中行的展示必须按照树的展开顺序来,即传递过来的List必须是有序的,且与树展开后的顺序一致
Please note that the plugin expects the rows in the HTML table to be in the same order in which they should be displayed in the tree. For example, suppose you have three nodes: A, B (child of node A) and C (child of node B). If you create rows for these nodes in your HTML table in the following order A - C - B, then the tree will not display correctly. You have to make sure that the rows are in the order A - B - C.
表格HTML代码示例:
<table> <tr data-tt-id="1"> <td>Parent</td> </tr> <tr data-tt-id="2" data-tt-parent-id="1"> <td>Child</td> </tr> </table>
Configuration
Settings
|
Setting |
Type |
Default |
Description |
|
branchAttr |
string |
"ttBranch" |
可选,强制打开节点的展开图标,允许将一个没有儿子节点的节点定义为分支节点,在HTML里面以data-tt-branch 属性形式展现. |
|
clickableNodeNames |
bool |
false |
默认false,点击展开图标打开子节点。设置为true时,点击节点名称也打开子节点. |
|
column |
int |
0 |
表中要展示为树的列数。 |
|
columnElType |
string |
"td" |
展示为树的单元格的类别(th,td or both). |
|
expandable |
bool |
false |
树是否可以展开,可以展开的树包含展开/折叠按钮。 |
|
expanderTemplate |
string |
<a href="#"> </a> |
展开按钮的html 片段。 |
|
indent |
int |
19 |
每个分支缩进的像素数。 |
|
indenterTemplate |
string |
<span class="indenter"></span> |
折叠按钮的HTML片段 |
|
initialState |
string |
"collapsed" |
初始状态,可选值: "expanded" or "collapsed". |
|
nodeIdAttr |
string |
"ttId" |
用来识别节点的数据属性的名称。在HTML里面以 data-tt-id 体现。 |
|
parentIdAttr |
string |
"ttParentId" |
用了设置父节点的数据属性的名称. 在HTML里面以data-tt-parent-id 体现。 |
|
stringCollapse |
string |
"Collapse" |
折叠按钮的title,国际化使用。 |
|
stringExpand |
string |
"Expand" |
展开按钮的title,国际化使用。 |
Events
|
Setting |
Type |
Default |
Description |
|
onInitialized |
function |
null |
树初始化完毕后的回调函数. |
|
onNodeCollapse |
function |
null |
节点折叠时的回调函数. |
|
onNodeExpand |
function |
null |
节点展开时的回调函数. |
|
onNodeInitialized |
function |
null |
节点初始化完毕后的回调函数 |
Public API
Plugin Function
treetable()
treetable() 方法可以传入下面的参数:
options(optional) : 一个描述配置的JS对象。
force(optional):参数为true时强制重新初始化树。
Additional Functions
对树操作的一些方法,附加方法必须通过treetable()方法调用。Eg:折叠id=42的节点, $("#tree").treetable("collapseNode", "42").
collapseAll():折叠所有节点
collapseNode(id):Collapse a single node, identified by id.
expandAll():Expand all nodes at once.
expandNode(id):Expand a single node, identified by id.
loadBranch(node, rows):向树中插入新行(<tr>s), 传入参数 node 为父节点,rows为待插入的行. 如果父节点node为null ,新行被作为父节点插入
move(nodeId, destinationId):Move node nodeId to new parent with destinationId.
node(id):Select a node from the tree. Returns a TreeTable.Node object.
removeNode(id):从树中移除某个节点及其所有子节点
reveal(id):展示树中的某个节点
sortBranch(node)
sortBranch(node, columnOrFunction):根据字母顺序对node 节点的所有子节点排序。Defaults to sorting on the values in the configured tree column (see settings). Pass an optional column number or sorting function as the second argument columnOrFunction. See the tests for examples of custom sorting functions. Does not recursively sort children of children.
unloadBranch(node):Remove nodes/rows (HTML <tr>s) from the tree, with parent node. Note that the parent (node) will not be removed.
Classes
HTML tr class:
expanded:标识节点被展开
collapsed:标识节点被折叠
branch:分支节点,有子节点或者拥有 branchAttr 属性
leaf:叶子节点,无子节点
Examples
Basic Static Tree :
$("#example-basic-static").treetable();
Basic Expandable Tree
$("#example-basic-expandable").treetable({ expandable: true });
Complex Tree With Drag and Drop
$("#example-advanced").treetable({ expandable: true }); // Highlight selected row $("#example-advanced tbody").on("mousedown", "tr", function() { $(".selected").not(this).removeClass("selected"); $(this).toggleClass("selected"); }); // Drag & Drop Example Code $("#example-advanced .file, #example-advanced .folder").draggable({ helper: "clone", opacity: .75, refreshPositions: true, revert: "invalid", revertDuration: 300, scroll: true }); $("#example-advanced .folder").each(function() { $(this).parents("#example-advanced tr").droppable({ accept: ".file, .folder", drop: function(e, ui) { var droppedEl = ui.draggable.parents("tr"); $("#example-advanced").treetable("move", droppedEl.data("ttId"), $(this).data("ttId")); }, hoverClass: "accept", over: function(e, ui) { var droppedEl = ui.draggable.parents("tr"); if(this != droppedEl[0] && !$(this).is(".expanded")) { $("#example-advanced").treetable("expandNode", $(this).data("ttId")); } } }); });
异步加载:
$("#treetable").treetable({ expandable: true,// 展示 initialState :"expanded",//默认打开所有节点 stringCollapse:'关闭', stringExpand:'展开', onNodeExpand: function() {// 分支展开后的回调函数 var node = this; //判断当前节点是否已经拥有子节点 var childSize = $("#treetable").find("[data-tt-parent-id='" + node.id + "']").length; if (childSize > 0) { return; } var data = "pageId=" + node.id; // Render loader/spinner while loading 加载时渲染 $.ajax({ loading : false, sync: false,// Must be false, otherwise loadBranch happens after showChildren? url : context + "/document/loadChild.json", data: data, success:function(result) { if(0 == result.code ){ if(!com.isNull(result.body)){ if(0 == eval(result.body['chilPages']).length){//不存在子节点 var $tr = $("#treetable").find("[data-tt-id='" + node.id + "']"); $tr.attr("data-tt-branch","false");// data-tt-branch 标记当前节点是否是分支节点,在树被初始化的时候生效 $tr.find("span.indenter").html("");// 移除展开图标 return; } var rows = this.getnereateHtml(result.body['chilPages']); $("#treetable").treetable("loadBranch", node, rows);// 插入子节点 $("#treetable").treetable("expandNode", node.id);// 展开子节点 } }else{ alert(result.tip); } } }); } });
Using treetable with PersistJS
https://github.com/jughead/jquery-treetable-ajax-persist/blob/master/example/index.html
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script type="text/javascript" src="../src/javascripts/jquery.treetable-ajax-persist.js"></script> <script type="text/javascript" src="../src/javascripts/jquery.treetable-3.0.0.js"></script> <script type="text/javascript" src="../src/javascripts/persist-min.js"></script> <link href="../src/stylesheets/jquery.treetable.css" media="all" rel="stylesheet" type="text/css" /> $("#treetable").agikiTreeTable({// treetable & persistJs persist: true, // 使用客户端缓存 /* * 客户端缓存文件名称:采用正则表达式:/^[a-z][a-z0-9_ -]+$/i 进行过滤, * 名称错误时直接throw new Error("Invalid name"); */ persistStoreName: "docFiles", // 其他属性同treetable });
jQuery.treetable使用及异步加载的更多相关文章
- jquery easyui easyui-treegrid 使用异步加载数据
jquery easyui easyui-treegrid 使用异步加载数据 jquery easyui easyui-treegrid 异步请求 >>>>>>&g ...
- jQuery+Ajax滚屏异步加载数据实现(附源码)
一.CSS样式 body { font:12px/1.0em Microsoft Yahei; line-height:1.6em; background:#fff; line-height:1.2e ...
- Jquery EasyUI tree 的异步加载(遍历指定文件夹,根据文件夹内的文件生成tree)
private void SMT(HttpContext context) { string SqlConnection82 = System.Configuration.ConfigurationM ...
- jquery load(URL,FUNCTION(){}) 异步加载页面
$("#btnSearch").click(function () { var queryUrl = '/Report/LoadInsClassifFileNew'; if ($( ...
- 动态加载(异步加载)jquery/MUI类库 页面加载完成后加载js类库
动态加载Mui类库: // ==UserScript== // @name // @version 1.4.0 // @author zzdhidden@gmail.com // @namespace ...
- JQuery ztree 异步加载实践
本来要做一个文件目录浏览界面,需要遍历所有的文件和目录,很显然一次性读取时很费时费力的一件事情. 因此就需要做异步加载.... 不过网上的几篇帖子还挺坑的!原始参考:JQuery异步加载实例,相对来说 ...
- Jquery zTree结合Asp.net实现异步加载数据
zTree结合Asp.net实现异步加载数据 实现简单操作 zTree 下载 api 访问 :http://www.ztree.me/v3/main.php 例子中用到json数据转化 newtons ...
- H5+JS+JQuery+ECharts实现异步加载
这几天,看了一下ECharts官网的API和Demo发现很有意思,于是就利用模型预测产生的数据做一个伪实时的动态数据显示 . 首先,创建一个index.html的文件,我用的vscode打开的,进行编 ...
- 【jquery】 在异步加载的元素上绑定事件
最近因为工作关系又重新回归到了jquery的怀抱,发现很多jquery的一些细节处理的部分都忘记了.这里记录一下最近在做项目时频繁遇到的一个问题:给异步加载的元素添加事件绑定. 问题发生的前提是项目前 ...
随机推荐
- 带头尾和动画的下拉刷新RecyclerView
项目地址:https://github.com/shichaohui/AnimRefreshRecyclerView 项目中包括一个demo(普通Androidproject)和Android Lib ...
- netty4与protocol buffer结合简易教程
各项目之间通常使用二进制进行通讯,占用带宽小.处理速度快~ 感谢netty作者Trustin Lee.让netty天生支持protocol buffer. 本实例使用netty4+protobuf-2 ...
- C++MFC编程笔记day01 MFC介绍、创建MFC程序和重写消息处理
一.MFC概念和作用 1.全称Microsoft Foundation Class Library,我们称为微软基础类库,封闭了绝大部分的win32 Api函数,C++语法中的数据结构,程序的运行流程 ...
- keepalived + lvs 网站高可用集群
一 ,四台服务器 master 端 : 192.168.1.3 backup 端: 192.168.1.4 REserver1 端 : 192.168.1.5 REserver2 端: 192.168 ...
- 演练:我的第一个 WPF 桌面应用程序 https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/getting-started/walkthrough-my-first-wpf-desktop-application
这篇文章演示如何开发简单的 Windows Presentation Foundation (WPF) 应用程序包括元素所共有的大多数 WPF 应用程序: 可扩展应用程序标记语言 (XAML) 标记. ...
- 图像处理之基础---滤波器之高斯低通滤波器的高斯模板生成c实现
()代码实现 对原图进行高斯平滑,去除图像中的计算噪声void Bmp::MakeGauss(double sigma,double **pdKernel,int *pnWindowSize){ // ...
- 关于编译(javac),import,package的再理解
1.若我们在A.java中用到了类B,当我们仅仅用 javac A.java 编译A时,编译器也会去寻找B,若类B依然是源文件,也会自动编译它.在使用javac和java命令时,有一个参数选项 -ve ...
- CSP 201612-4 压缩编码 【区间DP+四边形不等式优化】
问题描述 试题编号: 201612-4 试题名称: 压缩编码 时间限制: 3.0s 内存限制: 256.0MB 问题描述: 问题描述 给定一段文字,已知单词a1, a2, …, an出现的频率分别t1 ...
- 4.7.3 Canonical LR(1) Parsing Tables
4.7.3 Canonical LR(1) Parsing Tables We now give the rules for constructing the LR(1) ACTION and GOT ...
- bzoj [Usaco2010 Hol]cowpol 奶牛政坛【树链剖分】
意识流虚树 首先考虑只有一个党派,那么可以O(n)求树的直径,步骤是随便指定一个根然后找距离根最远点,然后再找距离这个最远点最远的点,那么最远点和距离这个最远点最远的点之间的距离就是直径 那么考虑多党 ...