<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>更正地址</title> <style> </style> <link href="https://www.jb51.net/layui/css/layui.css" > <script src="https://www.jb51.net/js/jquery-1.11.3.min.js"></script> <script src="https://www.jb51.net/layui/layui.js"></script> </head> <body> <div> 搜索商户: <div> <input autocomplete="off"> </div> <button data-type="reload">搜索</button> </div> <table lay-filter="menu-filter"></table> <script> layui.use('table', function() { var table = layui.table; //方法级渲染 table.render({ elem: '#tablea' ,url:'json/demo.json' , cols: [[ {field:'id', title: 'ID', align: 'center',width:150} ,{field:'username', title: '公司名称', align: 'center',width:100} ]] , id: 'testReload' , page: true , height: 600 ,request: { pageName: 'page' //页码的参数名称,默认:page ,limitName: 'pageSize' //每页数据量的参数名,默认:limit ,statusName:'status'//数据状态的字段名称,默认:code ,statusCode:200 //成功的状态码,默认:0 } }); $('.layui-btn').click(function () { var inputVal = $('.layui-input').val() table.reload('testReload', { url: 'https://www.easy-mock.com/mock/5c131015dada7b27ac3a5c36/titi/noData' // ,methods:"post" ,request: { pageName: 'page' //页码的参数名称,默认:page ,limitName: 'pageSize' //每页数据量的参数名,默认:limit } ,where: { query : inputVal } ,page: { curr: 1 } }); }) }) </script> </body> </html>
2.demo.json
{ "code": "0", "msg": "", "count": 1, "data": [ {"id":"1", "username": "海南信息有限公司" }, {"id":"2", "username": "海南信息有限公司" }, {"id":"3", "username": "海南信息有限公司" }, {"id":"4", "username": "海南信息有限公司" } ] }
效果:
点击搜索后