当前位置:   article > 正文

ztree 实现表格树_ztree 表格树

ztree 表格树

ztree节点固定显示用户自定义控件,转载的出处:http://www.jb51.net/article/124698.htm


  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" type="text/css" href="css/demo.css">
  5. <link rel="stylesheet" type="text/css" href="css/zTreeStyle/zTreeStyle.css">
  6. <script type="text/javascript" src="js/jquery-3.1.1.js"></script>
  7. <script type="text/javascript" src="js/jquery.ztree.all.js"></script>
  8. <script type="text/javascript" src="js/my.js"></script>
  9. <style>
  10. body {
  11. overflow: auto;
  12. }
  13. .ztree *{
  14. font-family: "微软雅黑","宋体",Arial, "Times New Roman", Times, serif;
  15. }
  16. .ztree {
  17. padding: 0;
  18. border-left: 1px solid #E3E3E3;
  19. border-right: 1px solid #E3E3E3;
  20. border-bottom: 1px solid #E3E3E3;
  21. }
  22. .ztree li a {
  23. vertical-align: middle;
  24. height: 32px;
  25. padding: 0px;
  26. }
  27. .ztree li > a {
  28. width: 100%;
  29. }
  30. .ztree li a.curSelectedNode {
  31. padding-top: 0px;
  32. background-color: #FFE6B0;
  33. border: 1px #FFB951 solid;
  34. opacity: 1;
  35. height: 32px;
  36. }
  37. .ztree li ul {
  38. padding-left: 0px
  39. }
  40. .ztree div.divTd span {
  41. line-height: 30px;
  42. vertical-align: middle;
  43. }
  44. .ztree div.divTd {
  45. height: 100%;
  46. line-height: 30px;
  47. border-top: 1px solid #E3E3E3;
  48. border-left: 1px solid #E3E3E3;
  49. text-align: center;
  50. display: inline-block;
  51. color: #6c6c6c;
  52. overflow: hidden;
  53. }
  54. .ztree div.divTd:first-child {
  55. text-align: left;
  56. text-indent: 10px;
  57. border-left: none;
  58. }
  59. .ztree .head {
  60. background: #E8EFF5;
  61. }
  62. .ztree .head div.divTd {
  63. color: #393939;
  64. font-weight: bold;
  65. }
  66. .ztree .ck{
  67. padding: 0 5px;
  68. margin: 2px 3px 7px 3px;
  69. }
  70. li:nth-child(odd){
  71. background-color:#F5FAFA;
  72. }
  73. li:nth-child(even){
  74. background-color:#FFFFFF;
  75. }
  76. </style>
  77. </head>
  78. <body>
  79. <div class="layer">
  80. <div id="tableMain">
  81. <ul id="dataTree" class="ztree" style="width:100%;height:100%">
  82. </ul>
  83. </div>
  84. </div>
  85. </body>
  86. </html>

my.js

  1. var newOpen =null;
  2. $(function () {
  3. //初始化数据
  4. var data = [{"id":"20170525091439001010","name":"企业注册","pId":null,"status":"1","typecode":"02"},{"id":"20170724174119005610","name":"部门沟通演练","pId":"20170525091439001010","status":"1","typecode":"2"},{"id":"20170725085455000110","name":"测试12","pId":null,"status":"1","typecode":"11"},{"id":"20170731171011000410","name":"审批流程","pId":null,"status":"1","typecode":"222"},{"id":"20170803133941018010","name":"单位登记","pId":null,"status":"1","typecode":"188"},{"id":"20170804085419000110","name":"模拟","pId":null,"status":"1","typecode":"122"},{"id":"20170809090321000110","name":"审批模拟(新)测试测试测试测试测试","pId":"20170525091439001010","status":"1","typecode":"110"},{"id":"20170809105407009210","name":"测测测测测测测测测测测测测测测测测测","pId":"20170809090321000110","status":"1","typecode":"123"},{"id":"20170814183837000210","name":"企业登记","pId":null,"status":"1","typecode":"111"},{"id":"20170822183437000710","name":"单事项-部门沟通","pId":"20170814183837000210","status":"1","typecode":"822"},{"id":"20170922112245000510","name":"23","pId":null,"status":"1","typecode":"03"},{"id":"20170922143810000010","name":"sdfa","pId":null,"status":"1","typecode":"04"},{"id":"20170922145203000110","name":"64526","pId":null,"status":"1","typecode":"34262"},{"id":"20170922155403001610","name":"333","pId":null,"status":"1","typecode":"33354"},{"id":"20170922171750000210","name":"4441234","pId":null,"status":"1","typecode":"44444"},{"id":"20170925160636007410","name":"测试数据","pId":"20170731171011000410","status":"1","typecode":"231"},{"id":"20170925163306007510","name":"23462111","pId":null,"status":"1","typecode":"2345"},{"id":"20170925163959007610","name":"242345","pId":"20170922112245000510","status":"1","typecode":"3625346"}];
  5. queryHandler(data);
  6. });
  7. var setting = {
  8. view: {
  9. showLine: false,
  10. addDiyDom: addDiyDom,
  11. },
  12. data: {
  13. simpleData: {
  14. enable: true
  15. }
  16. }
  17. };
  18. /**
  19. * 自定义DOM节点
  20. */
  21. function addDiyDom(treeId, treeNode) {
  22. var spaceWidth = 15;
  23. var liObj = $("#" + treeNode.tId);
  24. var aObj = $("#" + treeNode.tId + "_a");
  25. var switchObj = $("#" + treeNode.tId + "_switch");
  26. var icoObj = $("#" + treeNode.tId + "_ico");
  27. var spanObj = $("#" + treeNode.tId + "_span");
  28. aObj.attr('title', '');
  29. aObj.append('<div class="divTd swich fnt" style="width:60%"></div>');
  30. var div = $(liObj).find('div').eq(0);
  31. //从默认的位置移除
  32. switchObj.remove();
  33. spanObj.remove();
  34. icoObj.remove();
  35. //在指定的div中添加
  36. div.append(switchObj);
  37. div.append(spanObj);
  38. //隐藏了层次的span
  39. var spaceStr = "<span style='height:1px;display: inline-block;width:" + (spaceWidth * treeNode.level) + "px'></span>";
  40. switchObj.before(spaceStr);
  41. //图标垂直居中
  42. icoObj.css("margin-top","9px");
  43. switchObj.after(icoObj);
  44. var editStr = '';
  45. //宽度需要和表头保持一致
  46. editStr += '<div class="divTd" style="width:20%">' + (treeNode.typecode == null ? '' : treeNode.typecode ) + '</div>';
  47. editStr += '<div class="divTd" style="width:10%">' + (treeNode.status == '1' ? '有效' : '无效' ) + '</div>';
  48. editStr += '<div class="divTd" style="width:10%">' + opt(treeNode) + '</div>';
  49. aObj.append(editStr);
  50. }
  51. //初始化列表
  52. function queryHandler(zTreeNodes){
  53. //初始化树
  54. $.fn.zTree.init($("#dataTree"), setting, zTreeNodes);
  55. //添加表头
  56. var li_head = ' <li class="head"><a><div class="divTd" style="width:60%">类型名称</div><div class="divTd" style="width:20%">类型编码</div>' +
  57. '<div class="divTd" style="width:10%">是否有效</div><div class="divTd" style="width:10%">操作</div></a></li>';
  58. var rows = $("#dataTree").find('li');
  59. if (rows.length > 0) {
  60. rows.eq(0).before(li_head)
  61. } else {
  62. $("#dataTree").append(li_head);
  63. $("#dataTree").append('<li ><div style="text-align: center;line-height: 30px;" >无符合条件数据</div></li>')
  64. }
  65. }
  66. function opt(treeNode) {
  67. var htmlStr = '';
  68. htmlStr += '<input type="button" class="ck" οnclick="doEdit(\'' + treeNode.tId + '\',\'' + treeNode.id + '\')" value="编辑"/>';
  69. htmlStr += '<input type="button" class="ck" οnclick="doDelete(\'' + treeNode.tId + '\',\'' + treeNode.id + '\', \'' + treeNode.name + '\')" value="删除"/>';
  70. return htmlStr;
  71. }
仅供参考

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/322341
推荐阅读
相关标签
  

闽ICP备14008679号