Thinkphp+easyui 简单分页

一.HTML模板的编写

要点:
1. table class=”easyui-datagrid” 设定table样式以及JS
2. table pagination=”true” 开启分页
3. table url 设定table的数据来源,这里需要设定服务器接口的url地址.thinkphp使用U发方法进行生成
4. th field 设定服务器回传数据与table列的映射
5. 最重要的是,要引入样式与css.放到/项目/Public/easyui下

 <meta charset="UTF-8">
    <title>Basic CRUD Application - jQuery EasyUI CRUD Demo</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/demo/demo.css">
    <script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>

</head>

<body>
    <h2>Basic CRUD Application</h2>
    <p>Click the buttons on datagrid toolbar to do crud actions.</p>
    <table id="dg" url="{:U('Analysis/showAllDevicesInterface','','')}" class="easyui-datagrid"  title="My Users" pagination="true">
        <thead> 
            <tr>
                <th field="device_id" >Item ID</th>
                <th field="os_version" width="120">Product ID</th>
                <th field="manufacturer" width="80" align="right">List Price</th>
                <th field="model" width="80" align="right">Unit Cost</th>
                <th field="cpu_abi" width="200">Attribute</th>
                <th field="screen" width="60" align="center">Stauts</th>
            </tr>
        </thead>
    </table>

二. 显示模板的方法

  public function showAllReports() {
        $this->display();
    }

三. 服务器端接口的编写

要点
1. 浏览器js传输参数都服务器端,所以要求接受参数为 page=1, rows=10
2. 要求返回数据为json格式
{‘total’:12,’rows’:[数据]}

    public function showAllDevicesInterface($page=1,$rows=10) {
        $deviceModel = M('device_info');
        //统计所有数据总数
        $result["total"] =$deviceModel->count();
        //计算当前偏移值
        $offset=($page-1)*$rows;
        //查询指定分页的数据
        $devices = $deviceModel->limit($offset,$rows)->select();
        //设置入result
        $result['rows']=$devices;
        //返回json数据
        echo json_encode($result);
    }

参考地址:http://www.jeasyui.com/tutorial/datagrid/datagrid2.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值