You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Demo</title>
|
|
<!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
|
|
<link href="//unpkg.com/layui@2.9.9/dist/css/layui.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<table class="layui-hide" id="ID-table-demo-filter"></table>
|
|
|
|
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
|
|
<script src="//unpkg.com/layui@2.9.9/dist/layui.js"></script>
|
|
<script>
|
|
layui.use(function(){
|
|
var $ = layui.$;
|
|
var table = layui.table;
|
|
// 渲染
|
|
table.render({
|
|
elem: '#ID-table-demo-filter',
|
|
url:'/static/json/2/table/user.json', // 此处为静态模拟数据,实际使用时需换成真实接口
|
|
// toolbar: 'default',
|
|
height: 315,
|
|
cols: [function(){
|
|
var arr = [
|
|
{field:'id', title:'ID', width:80, fixed: 'left'},
|
|
{field:'username', title:'用户', width:120},
|
|
{field:'sex', title:'性别'},
|
|
{field:'city', title:'城市'},
|
|
{field:'sign', title:'签名'},
|
|
{field:'classify', title:'职业'}
|
|
];
|
|
|
|
// 初始化筛选状态
|
|
var local = layui.data('table-filter-test'); // 获取对应的本地记录
|
|
layui.each(arr, function(index, item){
|
|
if(item.field in local){
|
|
item.hide = local[item.field];
|
|
}
|
|
});
|
|
return arr;
|
|
}() ],
|
|
done: function(){
|
|
// 记录筛选状态
|
|
var that = this;
|
|
that.elem.next().on('mousedown', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]+', function(){
|
|
var input = $(this).prev()[0];
|
|
// 此处表名可任意定义
|
|
layui.data('table-filter-test', {
|
|
key: input.name
|
|
,value: input.checked
|
|
})
|
|
});
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |