59EasyUI 树形菜单- 树形网格添加分页

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用版 2核4GB 50GB
简介: 59EasyUI 树形菜单- 树形网格添加分页

本教程展示如何向带有动态加载特性的树形网格(TreeGrid)添加分页。

创建树形网格(TreeGrid)

启用树形网格(TreeGrid)的分页特性,必须添加 ‘pagination:true’ 属性,这样页面加载时就会向服务器发送 ‘page’ 和 ‘rows’ 参数。

<table title="Products" class="easyui-treegrid" style="width:700px;height:300px"
            data-options="
                url: 'treegrid4_getdata.php',
                rownumbers: true,
                pagination: true,
                pageSize: 2,
                pageList: [2,10,20],
                idField: 'id',
                treeField: 'name',
                onBeforeLoad: function(row,param){
                    if (!row) {    // load top level rows
                        param.id = 0;    // set id=0, indicate to load new page rows
                    }
                }
            ">
        <thead>
            <tr>
                <th field="name" width="250">Name</th>
                <th field="quantity" width="100" align="right">Quantity</th>
                <th field="price" width="150" align="right" formatter="formatDollar">Price</th>
                <th field="total" width="150" align="right" formatter="formatDollar">Total</th>
            </tr>
        </thead>
    </table>

服务器端代码

treegrid4_getdata.php
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
include 'conn.php';
$result = array();
if ($id == 0){
    $rs = mysql_query("select count(*) from products where parentId=0");
    $row = mysql_fetch_row($rs);
    $result["total"] = $row[0];
    $rs = mysql_query("select * from products where parentId=0 limit $offset,$rows");
    $items = array();
    while($row = mysql_fetch_array($rs)){
        $row['state'] = has_child($row['id']) ? 'closed' : 'open';
        array_push($items, $row);
    }
    $result["rows"] = $items;
} else {
    $rs = mysql_query("select * from products where parentId=$id");
    while($row = mysql_fetch_array($rs)){
        $row['state'] = has_child($row['id']) ? 'closed' : 'open';
        $row['total'] = $row['price']*$row['quantity'];
        array_push($result, $row);
    }
}
echo json_encode($result);
function has_child($id){
    $rs = mysql_query("select count(*) from products where parentId=$id");
    $row = mysql_fetch_array($rs);
    return $row[0] > 0 ? true : false;
}

发送到服务器的参数包括:

  1. page:要加载的当前页面。
  2. rows:页面尺寸大小。
  3. id:父行的 id 值,从服务器返回的行将被添加。

当展开一个行节点时,‘id’ 值是大于 0 的。 当改变页码时,‘id’ 值应该被设置为 0 来放置加载子行。


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
8月前
58EasyUI 树形菜单- 树形网格动态加载
58EasyUI 树形菜单- 树形网格动态加载
26 0
|
8月前
57EasyUI 树形菜单- 创建复杂树形网格
57EasyUI 树形菜单- 创建复杂树形网格
40 0
|
8月前
56EasyUI 树形菜单- 创建基础树形网格
56EasyUI 树形菜单- 创建基础树形网格
30 0
|
8月前
|
JavaScript
63EasyUI 表单 - 创建树形下拉框
63EasyUI 表单 - 创建树形下拉框
35 0
|
8月前
60EasyUI 树形菜单- 树形网格惰性加载节点
60EasyUI 树形菜单- 树形网格惰性加载节点
24 0
|
JavaScript 测试技术
Easyui 实现点击不同树节点打开不同tab页展示不同datagrid表数据设计
Easyui 实现点击不同树节点打开不同tab页展示不同datagrid表数据设计
92 0
|
JSON 前端开发 数据格式
EasyUI–树形控件tree详解
树形控件还是经常使用的,比如菜单、部门管理等涉及到有归属关系的功能经常在前端页面采用树形结构表示。 EasyUI对树形控件的封装非常的Nice,尤其是对复选框的支持简直是漂亮异常。本篇就最常用的菜单数为例演示EasyUI中tree的使用。 先看示意图:
564 0
EasyUI–树形控件tree详解

热门文章

最新文章