当前位置:编程学习 > JAVA >>

easyUI 在主datagrid上创建子datagrid

@author YHC

使用datagrid详细视图,用户可以展开一行去显示一个附加的详细信息,任何类容可以加载作为行详细,subgrid(子datagrid)也可以动态加载.这个教程将向你展示如何创建一个子grid在主grid上.

 \


查看  Demo

 

步骤 1: 创建主要的 DataGrid
[html]
<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>   

<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: 设置详细视图显示子grid
使用详细视图,切记引入view script js文件在你的页面的头部.


[html]
<script type="text/javascript" src="http://www.jeasyui.com/easyui/datagrid-detailview.js"></script>   

<script type="text/javascript" src="http://www.jeasyui.com/easyui/datagrid-detailview.js"></script>  [javascript] view plaincopyprint?$('#dg').datagrid({   
    view: detailview,   
    detailFormatter:function(index,row){   
        return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>';   
    },   
    onExpandRow: function(index,row){   
        $('#ddv-'+index).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);   
    }   
});   

$('#dg').datagrid({ 
    view: detailview, 
    detailFormatter:function(index,row){ 
        return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>'; 
    }, 
    onExpandRow: function(index,row){ 
        $('#ddv-'+index).datagrid({ 
            url:'datagrid22_getdetail.php?itemid='+row.it

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,