示例代码,有问题留言,我做详细解释,谢谢各位。

<table id="demo" class="layui-hide" lay-filter="test"></table>
        <script type="text/html" id="username">
            {{#  if(d.is_hide === 1){ }}
                {{d.username}}
            {{#  } }}
            {{#  if(d.is_hide === 2){ }}
                ****
            {{#  } }}
        </script>
        <script type="text/html" id="reply">
            {{#  if(d.msg_reply === null){ }}
                <i class="layui-icon"></i> 暂未回复
            {{#  } }}
            {{#  if(d.msg_reply != null){ }}
                {{d.msg_reply}}
            {{#  } }}
        </script>
        <script>
            layui.use('table', function(){
                var table = layui.table
                    , form = layui.form;
                //第一个实例
                table.render({
                    elem: '#demo'
                    //,height: 312
                    ,url: "{:url('index/msg/index')}" //数据接口
                    ,page: true //开启分页
                    ,response: {
                        statusCode: 200 //成功的状态码,默认:0
                    }
                    , size: 'lg' //sm小尺寸的表格 lg大尺寸
                    , cellMinWidth: 150
                    , limits: [5, 10, 15, 20, 25, 30]
                    , limit: "{:config('pages')}"
                    ,toolbar: '#toolbarDemo'
                    ,defaultToolbar: ['filter', 'exports'] //工具类
                    , loading: true
                    , id: 'test'
                    ,cols: [[ //表头
                        {field: 'id', title: 'ID', width:60, sort: true, fixed: 'left'}
                        ,{field: 'username', title: '用户名',templet:"#username",width:80}
                        ,{field: 'msg_con', title: '问题',}
                        ,{field: 'msg_reply', title: '回复',templet:"#reply"}
                        ,{field: 'create_time', title: '发布时间', sort: true}
                        ,{field: 'update_time', title: '回复时间', sort: true}
                    ]]
                });
                //监听搜索
                form.on('submit(LAY-search)', function (data) {
                    //执行重载
                    table.reload('test', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        ,where: data.field
                    });
                });
            });
        </script>

更多推荐

Layui加载Ajax表格table数据