网上相关资料非常少,我看过的大多是Extjs 3.0 急以前版本的解决方案。

比如:http://mikhailstadnik.com/ext/examples/nested-grid.htm  (Extjs3.0版本的)

但是4以后的就没看到了,经自己研究和参考官方网站资料,终于测试完成。现写下来供大家参考学习:

以下为简单的测试数据,如何做到更多功能,就看各位看官的功底了,哈。。。。。

效果图如下:

subgrid2.js文件:

Ext.define('Company', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id' },
{ name: 'company' },
{ name: 'price', type: 'float' },
{ name: 'change', type: 'float' },
{ name: 'pctChange', type: 'float' },
{ name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia' },
{ name: 'industry' },
{ name: 'desc' }
]
}); var dummyDataForMainGrid = [
['1', '3m Co', 71.72, 0.02, 0.03, '9/1 12:00am', 'Manufacturing'],
['2', 'Alcoa Inc', 29.01, 0.42, 1.47, '9/1 12:00am', 'Manufacturing'],
['3', 'Altria Group Inc', 83.81, 0.28, 0.34, '9/1 12:00am', 'Manufacturing'],
['4', 'American Express Company', 52.55, 0.01, 0.02, '9/1 12:00am', 'Finance']
]; var mainStore = Ext.create('Ext.data.ArrayStore', {
model: 'Company',
data: dummyDataForMainGrid
}); function displayInnerGrid(renderId) { //Model for the inside grid store
Ext.define('TestModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'Field1' },
{ name: 'Field2' },
{ name: 'Field3' }
]
}); //dummy data for the inside grid
var dummyDataForInsideGrid = [
['dummyRow1', 1, 2],
['dummyRow2', 1, 2],
['dummyRow3', 1, 3] ]; var insideGridStore = Ext.create('Ext.data.ArrayStore', {
model: 'TestModel',
data: dummyDataForInsideGrid
}); innerGrid = Ext.create('Ext.grid.Panel', {
store: insideGridStore,
selModel: {
selType: 'cellmodel'
},
columns: [
{ text: "Column1", dataIndex: 'Field1' },
{ text: "Column2", dataIndex: 'Field2' },
{ text: "Column3", dataIndex: 'Field3' }
],
columnLines: true,
autoWidth: true,
autoHeight: true,
//width: 400,
//height: 200,
frame: false,
iconCls: 'icon-grid',
renderTo: renderId
}); innerGrid.getEl().swallowEvent([
'mousedown', 'mouseup', 'click',
'contextmenu', 'mouseover', 'mouseout',
'dblclick', 'mousemove'
]); } function destroyInnerGrid(record) { var parent = document.getElementById(record.get('id'));
var child = parent.firstChild; while (child) {
child.parentNode.removeChild(child);
child = child.nextSibling;
} } Ext.define('MainGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.MainGrid',
store: mainStore,
columns: [
{ text: "Company", flex: 1, dataIndex: 'company' },
{ text: "Price", renderer: Ext.util.Format.usMoney, dataIndex: 'price' },
{ text: "Change", dataIndex: 'change' },
{ text: "% Change", dataIndex: 'pctChange' },
{ text: "Last Updated", renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange' }
],
//autoWidth: true,
selModel: {
selType: 'cellmodel'
},
//autoHeight: true,
plugins: [{
ptype: 'rowexpander',
rowBodyTpl: [
'<div id="{id}">',
'</div>'
]
}],
collapsible: true,
animCollapse: false,
title: 'Expander Rows in a Collapsable Grid',
iconCls: 'icon-grid',
//renderTo: Ext.getBody()
initComponent: function () {
var me = this;
this.callParent(arguments);
}
}); Ext.onReady(function () { Ext.QuickTips.init();
Ext.BLANK_IMAGE_URL = '/images/s.gif'; var mainGrid = new Ext.create('MainGrid'); mainGrid.view.on('expandBody', function (rowNode, record, expandRow, eOpts) {
displayInnerGrid(record.get('id'));
}); mainGrid.view.on('collapsebody', function (rowNode, record, expandRow, eOpts) {
destroyInnerGrid(record);
}); mainGrid.render(Ext.getBody());
mainGrid.setHeight(window.innerHeight);
mainGrid.setWidth(window.innerWidth);
Ext.EventManager.onWindowResize(function () {
//console.log('-------');
mainGrid.setHeight(window.innerHeight);
mainGrid.setWidth(window.innerWidth);
}); });

htm文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="/extjs4/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="/CSS/css.css" />
<link rel="stylesheet" type="text/css" href="/CSS/loading.css" />
<script type="text/javascript" src="/extjs4/ext-all.js"></script>
<script type="text/javascript" src="/extjs4/ux/RowExpander.js"></script>
<script type="text/javascript" src="/htm/test/subgrid2.js"></script>
</head>
<body> </body>
</html>

Extjs4.0.7 实现Grid的嵌套的更多相关文章

  1. MVC4.0 JSON JsonResult 序列化之后 对JSON 进行修改 EXTJS4.0 分页

    事情是这样的:我在MVC 下 前后台交互 用JsonResult 返回给前台使用. public JsonResult AjaxFindHospitalInfo() { List<T> l ...

  2. extjs4.0下的日期控件的星期显示为y的解决办法

    没有修改的时候的问题: 今天第一次写博客,就记录一下以前extjs4.2下运用日期组件的星期显示问题,当时找了n久,可能是extjs4.2才出来没多久,没有多少人发现这个问题或者说很少有人将Extjs ...

  3. 转: ASP.NET+ExtJs4.0+表单提交submit,上传图片到服务器

    http://blog.csdn.net/lmaohuanl/article/details/6792057 <!DOCTYPE html PUBLIC "-//W3C//DTD XH ...

  4. Swift2.0语言教程之函数嵌套调用形式

    Swift2.0语言教程之函数嵌套调用形式 Swift2.0语言函数嵌套调用形式 在Swift中,在函数中还能够调用函数,从而形成嵌套调用.嵌套调用的形式往往有两种:一种是在一个函数中调用其它函数:还 ...

  5. Swift2.0语言教程之类的嵌套与可选链接

    Swift2.0语言教程之类的嵌套与可选链接 Swift2.0语言类的嵌套 在一个类中可以嵌套一个或者多个类.它们的嵌套形式也是不同的,大致分为了两种:直接嵌套和多次嵌套.下面依次讲解这两种方式. S ...

  6. EXTJS4.0 grid 可编辑模式 配置

    首先配置这个参数 plugins:[//插件 Ext.create("Ext.grid.plugin.CellEditing",{ clicksToEdit:1//单元格 点一下就 ...

  7. ExtJS4.2学习(四)Grid表格中文排序问题(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-07/173.html --------------- ...

  8. ExtJS4.2学习(三)Grid表格(转)

    鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-07/172.html --------------- ...

  9. extjs6.0点击grid一行数据显示在一端的form中

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

随机推荐

  1. ASP.NET - cookie

    下面是写cookie  HttpCookie cookie = new HttpCookie("Info");//定义cookie对象以及名为Info的项  DateTime dt ...

  2. JS - 循环添加 DropDownList(Select)

    代码: <td style="padding-left: 10px;"> <select id="ddl_picture_3"> < ...

  3. Servlet的学习之Session(2)

    在上一篇中我们学习了Session对象默认在一个会话过程中,由服务器创建,能保存在这个会话过程中用户访问多个web资源时产生的需要保存的数据,并在访问服务器中其他web资源时可以将这些数据从Sessi ...

  4. 慎得慌二u赫然共和任务i个屁

    http://www.huihui.cn/share/8424421 http://www.huihui.cn/share/8424375 http://www.huihui.cn/share/842 ...

  5. MMA7455加速度传感器測量角度

    使用加速度传感器应该注意几点: 第一:确保你的IIC是正确的: 第二,首先必须校准系统,校准方法,例如以下:将7455平放,保证z轴向下,这是假设系统是Ok的,那么x轴输出为0,y轴输出为0,z轴输出 ...

  6. Struts2 学习笔记18 拦截器原理分析

    我们来进行一下拦截器的原理分析,从Struts2的源代码开始,然后我们手动创建一个项目进行模拟.(源代码需要下载然后添加好才能看到)我们可以用Debug来读源码. 从doFilter开始执行,流程如图 ...

  7. csdn发博文验证码缺陷

    csdn验证码的长处: 一,差点儿没有浪费人脑人力,却要花去机器人非常多cpu csdn发博文验证码却有非常大缺陷: 一.验证码的内容终于结果是简单的数字,能够穷举尽的,也就是说不怕被封号的话全然能够 ...

  8. Struts2获取演示示例教程

    回想Struts2的使用过程,网上搜的教程多多少少都会有点问题.又一次记录下创建过程,方便查阅. 1.下载Struts2的jar包 下载地址:http://archive.apache.org/dis ...

  9. 可编辑的表格:jQuery+PHP实现实时编辑表格字段内容

    在本例中,我们会通过jQuery实现单击将一个文本信息变为可编辑的表单,你可以对文本内容进行编辑,然后点击“确定”按钮,新的内容将发送到后台PHP程序处理,并保存到数据库:当点击“取消”按钮,则页面恢 ...

  10. 降低http请求次数

    80%的终于用户响应时间花在前端程序上.而其大部分时间则花在各种页面元素,如图像.样式表.脚本和Flash等的下载上. 降低页面元素将会降低HTTP请求次数.这是高速显示页面的关键所在. 1.Imag ...