不带分页的表格树

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE HTML>
 <html lang="zh-cn">
  
     <head>
         <meta charset="utf-8" />
         <meta http-equiv="X-UA-Compatible" content="IE=edge">
         <meta content="width=device-width,initial-scale=1.0" name="viewport">
         <meta content="yes" name="apple-mobile-web-app-capable">
         <meta content="black" name="apple-mobile-web-app-status-bar-style">
         <meta content="telephone=no" name="format-detection">
         <meta content="email=no" name="format-detection">
         <title>系统管理</title>
         <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
         <link href="https://cdn.bootcss.com/bootstrap-table/1.11.1/bootstrap-table.min.css" rel="stylesheet">
         <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-treegrid/0.2.0/css/jquery.treegrid.min.css">
     </head>
  
     <body>
         <div class="container">
             <h1>树形表格 : Table Treegrid</h1>
             <table id="table"></table>
             <br/>
         </div>
     </body>
     <script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
     <script src="https://cdn.bootcss.com/bootstrap-table/1.12.1/bootstrap-table.min.js"></script>
     <script src="https://cdn.bootcss.com/bootstrap-table/1.12.0/extensions/treegrid/bootstrap-table-treegrid.js"></script>
     <script src="https://cdn.bootcss.com/jquery-treegrid/0.2.0/js/jquery.treegrid.min.js"></script>
     <script type="text/javascript">
         var $table = $('#table');
         var data = [{
                 "time": "2019-08-27",
                 "id": 1,
                 "content": "内容1",
                 "pid": ""
             }, {
                 "time": "2019-08-27",
                 "id": 2,
                 "content": "内容2",
                 "pid": 1
             }, {
                 "time": "2019-08-27",
                 "id": 3,
                 "content": "内容3",
                 "pid": 1
             }, {
                 "time": "2019-08-27",
                 "id": 4,
                 "content": "内容4",
                 "pid": ""
             }, {
                 "time": "2019-08-27",
                 "id": 5,
                 "content": "内容5",
                 "pid": 2
             },
             {
                 "time": "2019-08-27",
                 "id": 6,
                 "content": "内容6",
                 "pid": ""
             },
             {
                 "time": "2019-08-27",
                 "id": 7,
                 "content": "内容7",
                 "pid": 6
             },
         ];
  
         $(function() {
             $table.bootstrapTable({
                 data: data,
                 idField: 'id',
                 dataType: 'jsonp',
                 columns: [{
                         field: 'time',
                         title: '时间',
                         width: 140
                     },
                     {
                         field: 'content',
                         title: '主要内容'
                     },
                 ],
  
                 //在哪一列展开树形
                 treeShowField: 'time',
                 //指定父id列
                 parentIdField: 'pid',
                 onResetView: function(data) {
                     //console.log('load');
                     $table.treegrid({
                         initialState: 'collapsed', // 所有节点都折叠
                         // initialState: 'expanded',// 所有节点都展开,默认展开
                         treeColumn: 0,
                         // expanderExpandedClass: 'glyphicon glyphicon-minus',  //图标样式
                         // expanderCollapsedClass: 'glyphicon glyphicon-plus',
                         onChange: function() {
                             $table.bootstrapTable('resetWidth');
                         }
                     });
                     //只展开树形的第一级节点
                     //$table.treegrid('getRootNodes').treegrid('expand');
  
                 },
             });
         });
     </script>

  

 


 

posted @   绝世大黄瓜  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示