42EasyUI 数据网格- 创建子网格

简介: 42EasyUI 数据网格- 创建子网格

本文将向您展示如何在主网格上创建一个子网格。

步骤 1:创建主网格

<table id="dg" style="width:700px;height:250px"
        url="datagrid22_getdata.php" 
        title="DataGrid - SubGrid"
        singleSelect="true" fitColumns="true">
    <thead>
        <tr>
            <th field="itemid" width="80">Item ID</th>
            <th field="productid" width="100">Product ID</th>
            <th field="listprice" align="right" width="80">List Price</th>
            <th field="unitcost" align="right" width="80">Unit Cost</th>
            <th field="attr1" width="220">Attribute</th>
            <th field="status" width="60" align="center">Status</th>
        </tr>
    </thead>
</table>
步骤 2:设置详细视图来显示子网

为了使用详细视图,请记得在页面头部引用视图脚本文件。

<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 style="padding:2px"><table class="ddv"></table></div>';
    },
    onExpandRow: function(index,row){
        var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
        ddv.datagrid({
            url:'datagrid22_getdetail.php?itemid='+row.itemid,
            fitColumns:true,
            singleSelect:true,
            rownumbers:true,
            loadMsg:'',
            height:'auto',
            columns:[[
                {field:'orderid',title:'Order ID',width:100},
                {field:'quantity',title:'Quantity',width:100},
                {field:'unitprice',title:'Unit Price',width:100}
            ]],
            onResize:function(){
                $('#dg').datagrid('fixDetailRowHeight',index);
            },
            onLoadSuccess:function(){
                setTimeout(function(){
                    $('#dg').datagrid('fixDetailRowHeight',index);
                },0);
            }
        });
        $('#dg').datagrid('fixDetailRowHeight',index);
    }
});

当用户点击展开按钮(’+’)时,‘onExpandRow’ 事件将被触发。 我们创建一个新的带有三列的子网格。 当子网格数据加载成功时或者改变尺寸大小时,请记得对主网格调用 ‘fixDetailRowHeight’ 方法。

目录
相关文章
|
9月前
29EasyUI 数据网格- 自定义排序
29EasyUI 数据网格- 自定义排序
24 0
|
9月前
31EasyUI 数据网格- 添加复选框
31EasyUI 数据网格- 添加复选框
44 0
31EasyUI 数据网格- 添加复选框
|
9月前
|
JSON 数据格式
44EasyUI 数据网格- 添加分页组件
44EasyUI 数据网格- 添加分页组件
22 0
|
9月前
|
前端开发
43EasyUI 数据网格- 使用虚拟滚动视图显示海量数据
43EasyUI 数据网格- 使用虚拟滚动视图显示海量数据
44 0
|
9月前
|
前端开发 容器
41EasyUI 数据网格- 扩展行显示细节
41EasyUI 数据网格- 扩展行显示细节
27 0
|
9月前
|
JSON 数据格式
40EasyUI 数据网格- 创建属性网格
40EasyUI 数据网格- 创建属性网格
30 0
|
9月前
39EasyUI 数据网格- 条件设置行背景颜色
39EasyUI 数据网格- 条件设置行背景颜色
32 0
|
9月前
38EasyUI 数据网格- 创建页脚摘要
38EasyUI 数据网格- 创建页脚摘要
25 0
|
9月前
37EasyUI 数据网格- 创建自定义视图
37EasyUI 数据网格- 创建自定义视图
31 0
|
9月前
36EasyUI 数据网格- 合并单元格
36EasyUI 数据网格- 合并单元格
19 0

热门文章

最新文章