EasyUI-datagrid分页向后台传什么参数以及后台需返回什么参数给前台问题回答

1.创建表格。url指后台接收请求的链接,注意设置pagination="true"分页才会显示。分页会向后台发送2个参数:

page:表示当前页数

rows:表示一页显示多少条记录


<table id="tt" class="easyui-datagrid" style="width:600px;height:250px"
url="datagrid2_getdata.php"
title="Load Data" iconCls="icon-save"
rownumbers="true" pagination="true">
<thead>
<tr>
<th field="itemid" width="80">Item ID</th>
<th field="productid" width="80">Product ID</th>
<th field="listprice" width="80" align="right">List Price</th>
<th field="unitcost" width="80" align="right">Unit Cost</th>
<th field="attr1" width="150">Attribute</th>
<th field="status" width="60" align="center">Stauts</th>
</tr>
</thead>
</table>

2.后台接收page和rows参数用于计算从mysql数据库里的第几条开始取,取多少条。
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
// ...
$rs = mysql_query("select count(*) from item");
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];
 
$rs = mysql_query("select * from item limit $offset,$rows");
 
$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;
 
echo json_encode($result);

3.返回json包含total和rows两部分,即可实现分页效果
{
  "total": "28",
  "rows": [
    {
      "itemid": "EST-19",
      "productid": "AV-SB-02",
      "listprice": "15.50",
      "unitcost": "2.00",
      "status": "P",
      "attr1": "Adult Male"
    },
    {
      "itemid": "EST-2",
      "productid": "FI-SW-01",
      "listprice": "16.50",
      "unitcost": "10.00",
      "status": "P",
      "attr1": "Small"
    },
    {
      "itemid": "EST-20",
      "productid": "FI-FW-02",
      "listprice": "5.50",
      "unitcost": "2.00",
      "status": "P",
      "attr1": "Adult Male"
    },
    {
      "itemid": "EST-21",
      "productid": "FI-FW-02",
      "listprice": "5.29",
      "unitcost": "1.00",
      "status": "P",
      "attr1": "Adult Female"
    },
    {
      "itemid": "EST-22",
      "productid": "K9-RT-02",
      "listprice": "135.50",
      "unitcost": "100.00",
      "status": "P",
      "attr1": "Adult Male"
    },
    {
      "itemid": "EST-23",
      "productid": "K9-RT-02",
      "listprice": "145.49",
      "unitcost": "100.00",
      "status": "P",
      "attr1": "Adult Female"
    },
    {
      "itemid": "EST-24",
      "productid": "K9-RT-02",
      "listprice": "255.50",
      "unitcost": "92.00",
      "status": "P",
      "attr1": "Adult Male"
    },
    {
      "itemid": "EST-25",
      "productid": "K9-RT-02",
      "listprice": "325.29",
      "unitcost": "90.00",
      "status": "P",
      "attr1": "Adult Female"
    },
    {
      "itemid": "EST-26",
      "productid": "K9-CW-01",
      "listprice": "125.50",
      "unitcost": "92.00",
      "status": "P",
      "attr1": "Adult Male"
    },
    {
      "itemid": "EST-27",
      "productid": "K9-CW-01",
      "listprice": "155.29",
      "unitcost": "90.00",
      "status": "P",
      "attr1": "Adult Female"
    }
  ]
}
 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值