Home > Article > Web Front-end > How to automatically refresh layui tables
Step one: Set up the environment.
1. The environment setup of layui is very simple, similar to query. It can be used directly as long as it is imported.
1.1: Introduce js and styles
2. If you make a complete interactive request the day before and after, you need to build a responsive background environment. (This article does not introduce the construction of the background environment)
Step 2: Download layui.
Website: https://www.layui.com/
1. The first step is to open the layui download URL
2. Download the layui dependency package
3. Check the dependency packages.
Related recommendations: "layui Framework Tutorial"
Step 3: Code implementation.
1. Implementation of html code part
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;"> <legend>人员数据</legend> </fieldset> <table class="layui-hide" id="demo" lay-filter="pManageTable"></table> <script type="text/html" id="barDemo"> <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a> <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a> <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> </script>
2. Implementation of js code.
<script src="layui/layui.all.js" charset="utf-8"></script> <script> layui.config({ version: '1545041465443' //为了更新 js 缓存,可忽略 }); layui.use(['laydate', 'laypage', 'table', 'element'], function(){ var laydate = layui.laydate //日期 ,laypage = layui.laypage //分页 ,table = layui.table //表格 ,element = layui.element //元素操作 //默认第一次初始化调用执行一个 table 实例 var tableIns = table.render({ elem: '#demo' ,height: 450 ,url:'demo.json' //数据接口 ,title: '用户表' ,page: true //开启分页 ,toolbar: 'default' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档 ,totalRow: true //开启合计行 ,cols: [[ //表头 {type: 'checkbox', fixed: 'left'} ,{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'} ,{field: 'username', title: '菜品名称', width:105} ,{field: 'sex', title: '菜单类别', width: 105, sort: true} ,{field: 'city', title: '所属菜系', width:115, sort: true} ,{field: 'sign', title: '签名', width: 80, sort: true, totalRow: true} ,{field: 'experience', title: '积分', width: 85, sort: true, totalRow: true} ,{field: 'score', title: '评分', width: 100} ,{field: 'classify', title: '职业', width: 100} ,{field: 'wealth', title: '财富', width: 100} ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'} ]] });
The button or js is called regularly, and the query button is called
function callBack(){ //第二次调用 tableIns.reload({ where: {'username':"user-0"}/设定异步数据接口的额外参数,任意设 ,page: { curr: 1 //重新从第 1 页开始 } }); } });
Step 4: Test.
1. Open the page data table and display successfully.
2. Click the page number of the page turning button to refresh the table
3. Call layui's request to refresh the page.
The above is the detailed content of How to automatically refresh layui tables. For more information, please follow other related articles on the PHP Chinese website!