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
|
<script src="/static/vendor/layuimini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
layui.use(['form', 'table'], function () {
var $ = layui.jquery,
form = layui.form,
table = layui.table;
table.render({
elem: '#currentTableId',
url: '/user/queryjson',
toolbar: '#toolbarDemo',
defaultToolbar: ['filter', 'exports', 'print', {
title: '提示',
layEvent: 'LAYTABLE_TIPS',
icon: 'layui-icon-tips'
}],
cols: [[
{type: "checkbox", width: 50},
{field: 'id', width: 80, title: 'ID', sort: true},
{field: 'name', width: 80, title: '用户名'},
{field: 'sex', width: 80, title: '性别', sort: true, templet: sexFormat},
{field: 'tel', width: 120, title: '联系方式'},
{field: 'addr', width: 120, title: '地址'},
{field: 'birthday', width: 180, title: '生辰', templet: birFormat},
{title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
]],
limits: [10, 15, 20, 25, 50, 100],
limit: 15,
page: true,
skin: 'line'
});
// 格式化显示男女信息,后端返回 true 或者 false,这里做判断
function sexFormat(d) {
var str;
if (d.sex) {
str = '男';
} else {
str = '女';
}
return str;
}
// 格式化显示日期,调用layui.util 工具集,参考:https://www.layui.com/doc/modules/util.html
function birFormat(d) {
birday = layui.util.toDateString(d.birthday, "yyyy-MM-dd");
return birday;
}
});
</script>
|