地质所 沉降监测网建设项目
zmk
2024-05-15 9e3afc6d0fa514f986d3fea40fa23124e6fb5070
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('动态增删改查')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="insertRow()">
                <i class="fa fa-plus"></i> 新增行
            </a>
            <a class="btn btn-danger multiple disabled" onclick="removeRow()">
                <i class="fa fa-remove"></i> 删除选择行
            </a>
            <a class="btn btn-danger" onclick="removeRowByUniqueId()">
                <i class="fa fa-remove"></i> 根据值删除行
            </a>
            <a class="btn btn-danger" onclick="removeRowAll()">
                <i class="fa fa-remove"></i> 删除所有行
            </a>
            <a class="btn btn-info" onclick="updateRow()">
                <i class="fa fa-edit"></i> 修改行
            </a>
            <a class="btn btn-info" onclick="updateRowByUniqueId()">
                <i class="fa fa-edit"></i> 根据值修改行
            </a>
            <a class="btn btn-info" onclick="getSelections()">
                <i class="fa fa-search"></i> 查询选择数据
            </a>
            <a class="btn btn-info" onclick="getRowByUniqueId()">
                <i class="fa fa-search"></i> 根据值查询行
            </a>
            <a class="btn btn-primary" onclick="getData()">
                <i class="fa fa-search"></i> 查询所有数据
            </a>
        </div>
        <div class="row">
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var prefix = ctx + "demo/table";
        
        $(function() {
            var options = {
                url: prefix + "/list",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                pagination: false,
                uniqueId: "userId",
                height: 400,
                columns: [{
                    checkbox: true
                },
                {
                    field : 'userId', 
                    title : '用户ID'
                },
                {
                    field : 'userCode', 
                    title : '用户编号'
                },
                {
                    field : 'userName', 
                    title : '用户姓名'
                },
                {
                    field : 'userPhone', 
                    title : '用户手机'
                },
                {
                    field : 'userEmail', 
                    title : '用户邮箱'
                },
                {
                    field : 'userBalance',
                    title : '用户余额'
                }]
            };
            $.table.init(options);
        });
        
        /* 新增表格行 */
        function insertRow(){
            var randomId = 100 + ~~(Math.random() * 100)
            $("#" + table.options.id).bootstrapTable('insertRow', {
                index: 0, // 你想插入到哪,0表示第一行
                row: {
                    userId: randomId,
                    userCode: 2000000 + randomId,
                    userName: '测试' + randomId,
                    userPhone: '1588888888',
                    userEmail: 'ry1@qq.com',
                    userBalance: 10 + randomId,
                }
            })
        }
        
        /* 删除指定表格行 */
        function removeRow(){
            var ids = $.table.selectColumns("userId");
            if (ids.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $("#" + table.options.id).bootstrapTable('remove', {
                field: 'userId',
                values: ids
            })
        }
        
        /* 删除行ID值为1的数据 */
        function removeRowByUniqueId(){
            $("#" + table.options.id).bootstrapTable('removeByUniqueId', 1)
        }
        
        /* 删除所有表格行 */
        function removeRowAll(){
            $("#" + table.options.id).bootstrapTable('removeAll')
        }
        
        /* 修改表格行 */
        function updateRow(){
            var randomId = 100 + ~~(Math.random() * 100)
            $("#" + table.options.id).bootstrapTable('updateRow', {
                index: 0, // 你想修改哪行,0表示第一行
                row: {
                    userId: randomId,
                    userCode: 3000000 + randomId,
                    userName: '测试' + randomId,
                    userPhone: '1599999999',
                    userEmail: 'ry2@qq.com',
                    userBalance: 50 + randomId,
                }
            })
        }
        
        /* 修改行ID值为1的数据 */
        function updateRowByUniqueId(){
            var randomId = 100 + ~~(Math.random() * 100)
            $("#" + table.options.id).bootstrapTable('updateByUniqueId', {
                id: 1,
                row: {
                    userId: randomId,
                    userCode: 3000000 + randomId,
                    userName: '测试' + randomId,
                    userPhone: '1599999999',
                    userEmail: 'ry2@qq.com',
                    userBalance: 50 + randomId,
                }
            })
        }
        
        /* 查询表格所有数据值 */
        function getData(){
            var data = $("#" + table.options.id).bootstrapTable('getData');
            alert(JSON.stringify(data))
        }
        
        /* 查询行ID值为1的数据 */
        function getRowByUniqueId(){
            var data = $("#" + table.options.id).bootstrapTable('getRowByUniqueId', 1);
            alert(JSON.stringify(data))
        }
        
        /* 查询表格选择行数据值 */
        function getSelections(){
            var data = $("#" + table.options.id).bootstrapTable('getSelections');
            alert(JSON.stringify(data))
        }
    </script>
</body>
</html>