Files
aurora-admin/frameworks/FixedColumnTable.html
T

60 lines
2.8 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Aurora Admin · FixedColumnTable</title>
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css" />
<link rel="stylesheet" href="./FixedColumnTable.css" />
</head>
<body>
<div class="aa-page">
<h2 class="aa-h2">FixedColumnTable 固定列表格</h2>
<p class="aa-desc">列过多时左右列固定,横向滚动查看其余列,固定列带阴影分隔,支持固定表头。</p>
<div class="aa-demo">
<div class="aa-demo__title">宽表(左固定「姓名」,右固定「操作」)</div>
<div class="aa-fixtable-wrap">
<table class="aa-fixtable" id="fixtable">
<thead><tr id="fixhead"></tr></thead>
<tbody id="fixbody"></tbody>
</table>
</div>
<div class="aa-hint">← 向左滚动可查看被固定的左列 / 右列 →</div>
</div>
</div>
<script>
var cols = [
{ key: 'name', title: '姓名', fixed: 'left', w: 100 },
{ key: 'dept', title: '部门', w: 120 },
{ key: 'role', title: '角色', w: 120 },
{ key: 'email', title: '邮箱', w: 200 },
{ key: 'phone', title: '电话', w: 140 },
{ key: 'city', title: '城市', w: 120 },
{ key: 'join', title: '入职', w: 120 },
{ key: 'status', title: '状态', w: 100 },
{ key: 'op', title: '操作', fixed: 'right', w: 120 }
];
var data = [
{ name: '王伟', dept: '华东大区', role: '销售经理', email: 'wangwei@demo.com', phone: '13800000001', city: '上海', join: '2021-03', status: '在职', op: '编辑' },
{ name: '李娜', dept: '华南大区', role: '销售', email: 'lina@demo.com', phone: '13800000002', city: '广州', join: '2022-07', status: '在职', op: '编辑' },
{ name: '张强', dept: '华北大区', role: '售前', email: 'zhangq@demo.com', phone: '13800000003', city: '北京', join: '2020-11', status: '休假', op: '编辑' },
{ name: '陈静', dept: '研发中心', role: '工程师', email: 'chenj@demo.com', phone: '13800000004', city: '深圳', join: '2023-01', status: '在职', op: '编辑' }
];
document.getElementById('fixhead').innerHTML = cols.map(function (c) {
var cls = c.fixed ? 'aa-fixed aa-fixed-' + c.fixed : '';
return '<th class="' + cls + '" style="min-width:' + c.w + 'px">' + c.title + '</th>';
}).join('');
document.getElementById('fixbody').innerHTML = data.map(function (d) {
return '<tr>' + cols.map(function (c) {
var cls = c.fixed ? 'aa-fixed aa-fixed-' + c.fixed : '';
return '<td class="' + cls + (c.key === 'status' && d.status !== '在职' ? ' is-muted' : '') + '">' + d[c.key] + '</td>';
}).join('') + '</tr>';
}).join('');
</script>
</body>
</html>