欢迎光临
感谢一路有你

layui-table-ajax-php显示数据

如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
 
public function cp_list()
{

    if ($this->request->isAjax()) {
        $map = [];
        $keyword = $this->request->param('keyword');
        $page = $this->request->param('page/d', 1);
        $limit = $this->request->param('limit/d', 20);
        if ($keyword) {
             $map["name"] = ['like', '%'.$keyword.'%'];
        }
        $data['data'] = model('products')->alias('a')
            ->field('a.*,b.nick as store')
            ->join('dianpu b','a.sid=b.id','left')
            ->where($map)->page($page)->limit($limit)->order("id desc")->select();
        //echo db('products')->getLastSql();
        $data['count'] = model('products')->where($map)->count('id');
        $data['code'] = 0;
        return json($data);
    }

    return $this->fetch();
}


<style type="text/css">
    .layui-table-body{overflow-x:auto;}
    .layui-table-cell{font-size:12px;}
</style>
<div class="page-toolbar">
    <div class="page-filter fr">
        <form class="layui-form layui-form-pane" action="{:url()}" id="hisiSearch" method="get">
            <div class="layui-form-item">
                <label class="layui-form-label">搜索</label>
                <div class="layui-input-inline">
                    <input type="text" name="keyword" value="" lay-verify="required" placeholder="Nick" autocomplete="off" class="layui-input">
                </div>
            </div>
        </form>
    </div>
    <div class="layui-btn-group fl">
        <a href="{:url('cp_info')}" class="layui-btn layui-btn-primary layui-icon layui-icon-add-circle-fine">&nbsp;添加</a>
        <a data-href="{:url('status?table=products&val=1')}" class="layui-btn layui-btn-primary j-page-btns layui-icon layui-icon-play" data-table="dataTable">&nbsp;启用</a>
        <a data-href="{:url('status?table=products&val=0')}" class="layui-btn layui-btn-primary j-page-btns layui-icon layui-icon-pause" data-table="dataTable">&nbsp;禁用</a>
        <a data-href="{:url('del?table=products')}" class="layui-btn layui-btn-primary j-page-btns confirm layui-icon layui-icon-close red">&nbsp;删除</a>

    </div>
    <!-- <form action="/admin.php/admin/products/excelReader.html" method="post" enctype="multipart/form-data">
         <input type="file" class="file1" name="file" />
         <button type="submit" class="but1">上传</button>
    </form> -->
</div>
<form id="pageListForm">
    <div class="layui-form">
        <table id="dataTable"></table>
        <script type="text/html" id="usernameTpl">
            <p class="ml10 fl"><strong class="mcolor">{{ d.name }}</strong></p>
        </script>
        <script type="text/html" id="statusTpl">
            <input type="checkbox" name="status" value="{{ d.status }}" lay-skin="switch" lay-filter="switchStatus" lay-text="上架|下架" {{ d.status == 1 ? 'checked' : '' }} data-href="{:url('status')}?table=products&id={{ d.id }}">
        </script>
        <script type="text/html" title="操作按钮模板" id="buttonTpl">
            <a href="{:url('cp_info')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal">修改</a><a href="{:url('del?table=products')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
        </script>
    </div>
</form>
{include file="block/layui" /}
<script type="text/javascript">
    layui.use(['table'], function() {
        var table = layui.table;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'Name', title: 'Name', templet: '#usernameTpl'}
                ,{field: 'ItemNo', title: 'ItemNo', templet: function(d){
                    return d.itemno;
                }}
                ,{field: 'Store', title: 'Store', templet: function(d){
                    return d.store;
                }}
                ,{field: 'stock', title: 'Stock', templet: function(d){
                    return d.stock;
                }}

                ,{field: 'status', title: '状态', width: 100, templet: '#statusTpl'}
                ,{title: '操作', width: 120, templet: '#buttonTpl'}
            ]]
        });
    });
</script>

 

赞(1) 打赏
未经允许不得转载:王明昌博客 » layui-table-ajax-php显示数据
分享到: 更多 (0)

相关推荐

  • 暂无文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

×
订阅图标按钮