首页 技术 正文
技术 2022年11月15日
0 收藏 626 点赞 2,962 浏览 2179 个字

http://blog.csdn.net/yanghongchang_/article/details/7854156原著

datagrid 可以改变它的view(视图)去显示不同的效果.使用详细视图,datagrid可以显示展开按钮(“+” 或者 “-“)在数据行的左边,用户可以展开一个行去显示一个附加的详细信息.

easyUI 展开DataGrid里面的行显示详细信息

查看 Demo

步骤 1: 创建 DataGrid

  1. <table id=”dg” style=”width:500px;height:250px” url=”data/datagrid_data.json” title=”DataGrid – Expand Row” singleselect=”true” fitcolumns=”true”>
  2. <thead>
  3. <tr>
  4. <th field=”itemid” width=”60″>Item ID</th>
  5. <th field=”productid” width=”80″>Product ID</th>
  6. <th field=”listprice” align=”right” width=”70″>List Price</th>
  7. <th field=”unitcost” align=”right” width=”70″>Unit Cost</th>
  8. <th field=”status” width=”50″ align=”center”>Status</th>
  9. </tr>
  10. </thead>
  11. </table>

步骤 2: 为DataGrid设置详细视图

使用详细视图,切记:引入视图script文件在你的页面的头部.

  1. <script type=”text/javascript” src=”http://www.jeasyui.com/easyui/datagrid-detailview.js”></script>
  1. $(‘#dg’).datagrid({
  2. view: detailview,
  3. detailFormatter:function(index,row){
  4. return ‘<div id=”ddv-‘ + index + ‘” style=”padding:5px 0″></div>’;
  5. },
  6. onExpandRow: function(index,row){
  7. $(‘#ddv-‘+index).panel({
  8. border:false,
  9. cache:false,
  10. href:’datagrid21_getdetail.php?itemid=’+row.itemid,
  11. onLoad:function(){
  12. $(‘#dg’).datagrid(‘fixDetailRowHeight’,index);
  13. }
  14. });
  15. $(‘#dg’).datagrid(‘fixDetailRowHeight’,index);
  16. }
  17. });

我们定义detailFormatter函数告诉datagrid 如何渲染详细视图,在这种情况下,我们返回一个简单的 ‘<div>’元素,它将充当最为一个详细内容的容器,

注意:详细信息为空,当用户点击展开按钮(‘+’),onExpandRow事件将被触发,所以我们可以写一些代码去加载ajax详细内容,最后我们调用fixDetailRowHeight方法去固定行高度,当详细内容加载之后.

步骤 3: 服务器端代码

datagrid21_getdetail.php

  1. <?php
  2. $itemid = $_REQUEST[‘itemid’];
  3. $content = file_get_contents(‘data/datagrid_data.json’);
  4. $data = json_decode($content,true);
  5. foreach($data[‘rows’] as $item){
  6. if ($item[‘itemid’] == $itemid){
  7. break;
  8. }
  9. }
  10. ?>
  11. <table class=”dv-table” border=”0″ style=”width:100%;”>
  12. <tr>
  13. <td rowspan=”3″ style=”width:60px”>
  14. <?php
  15. echo “<img src=\”images/$itemid.gif\” style=\”height:50px\”/>”;
  16. ?>
  17. </td>
  18. <td class=”dv-label”>Item ID: </td>
  19. <td><?php echo $item[‘itemid’];?></td>
  20. <td class=”dv-label”>Product ID:</td>
  21. <td><?php echo $item[‘productid’];?></td>
  22. </tr>
  23. <tr>
  24. <td class=”dv-label”>List Price: </td>
  25. <td><?php echo $item[‘listprice’];?></td>
  26. <td class=”dv-label”>Unit Cost:</td>
  27. <td><?php echo $item[‘unitcost’];?></td>
  28. </tr>
  29. <tr>
  30. <td class=”dv-label”>Attribute: </td>
  31. <td colspan=”3″><?php echo $item[‘attr1’];?></td>
  32. </tr>
  33. </table>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844