jQuery EasyUI 数据网格 – 扩展行显示细节
2023-02-18 15:32:05 时间
jQuery EasyUI 数据网格 - 扩展行显示细节
数据网格(datagrid)可以改变它的视图(view)来显示不同的效果。使用详细视图,数据网格(datagrid)可以在数据行的左边显示展开按钮("+" 或者 "-")。用户可以展开行来显示附加的详细信息。
![](/wp-content/uploads/2013/12/datagrid21.png)
步骤 1:创建数据网格(DataGrid)
<table id="dg" style="width:500px;height:250px" url="datagrid8_getdata.php" pagination="true" sortName="itemid" sortOrder="desc" title="DataGrid - Expand Row" singleSelect="true" fitColumns="true"> <thead> <tr> <th field="itemid" width="60">Item ID</th> <th field="productid" width="80">Product ID</th> <th field="listprice" align="right" width="70">List Price</th> <th field="unitcost" align="right" width="70">Unit Cost</th> <th field="status" width="50" align="center">Status</th> </tr> </thead> </table>
步骤 2:为数据网格(DataGrid)设置详细视图
为了使用详细视图,请记得在页面头部引用视图脚本文件。
<script type="text/javascript" src="http://www.w3cschool.cc/try/jeasyui/datagrid-detailview.js"></script>
$('#dg').datagrid({ view: detailview, detailFormatter:function(index,row){ return '<div class="ddv" style="padding:5px 0"></div>'; }, onExpandRow: function(index,row){ var ddv = $(this).datagrid('getRowDetail',index).find('div.ddv'); ddv.panel({ border:false, cache:false, href:'datagrid21_getdetail.php?itemid='+row.itemid, onLoad:function(){ $('#dg').datagrid('fixDetailRowHeight',index); } }); $('#dg').datagrid('fixDetailRowHeight',index); } });
我们定义 'detailFormatter' 函数,告诉数据网格(datagrid)如何渲染详细视图。 在这种情况下,我们返回一个简单的 '<div>' 元素,它将充当详细内容的容器。 请注意,详细信息为空。当用户点击展开按钮('+')时,onExpandRow 事件将被触发。 所以我们可以写一些代码来加载 ajax 详细内容。 最后我们调用 'fixDetailRowHeight' 方法来固定当详细内容加载时的行高度。
步骤 3:服务器端代码
datagrid21_getdetail.php
<?php include_once 'conn.php'; $itemid = mysql_real_escape_string($_REQUEST['itemid']); $rs = mysql_query("select * from item where itemid='$itemid'"); $item = mysql_fetch_array($rs); ?> <table class="dv-table" border="0" style="width:100%;"> <tr> <td rowspan="3" style="width:60px"> <?php $aa = explode('-',$itemid); $serno = $aa[1]; $img = "images/shirt$serno.gif"; echo "<img src=\"$img\" style=\"width:60px;margin-right:20px\" />"; ?> </td> <td class="dv-label">Item ID: </td> <td><?php echo $item['itemid'];?></td> <td class="dv-label">Product ID:</td> <td><?php echo $item['productid'];?></td> </tr> <tr> <td class="dv-label">List Price: </td> <td><?php echo $item['listprice'];?></td> <td class="dv-label">Unit Cost:</td> <td><?php echo $item['unitcost'];?></td> </tr> <tr> <td class="dv-label">Attribute: </td> <td colspan="3"><?php echo $item['attr1'];?></td> </tr> </table>
下载 jQuery EasyUI 实例
jeasyui-datagrid-datagrid21.zip
相关文章
- Centos8安装Mariadb出现mysql_secure_installation: command not found的解决办法
- 基于 Docker 搭建 MySQL 一主两从复制
- MySQL运行机制原理与架构
- Mysql——分组统计
- Mysql——字符串函数
- 牛客刷题——Mysql系列
- MYSQL——JBDC实现增删改查
- 数据库基础,看完这篇就够了!
- MySQL不要再用utf8了
- 快速学会慢查询SQL排查
- Android破解心得——记学习七少月安卓大型安全公开课
- 新特性解读 | MySQL 8.0.31 导入直方图存量数据
- 【Qbot】4.连接mysql/限制使用次数
- MySQL 为什么要使用索引及索引创建的原则有哪些?
- MySQL 6种索引数据结构详解:BTree、B+Tree、红黑树、平衡二叉树、二叉树、Hash
- MySQL 聚集索引(InnoDB)和 非聚集索引(MyISAM) 精讲~两张图彻底搞懂
- MySQL 事务隔离级别 理论+实战分析
- MySQL MVCC 多版本并发控制机制 工作原理
- MySQL : 彻底搞懂一条SQL的执行过程
- 彻底搞懂MySQL主从复制工作原理 2+3+3+4