Expandable DataGrid

by melane

HTML

<script src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<script src="http://www.jeasyui.com/easyui/datagrid-detailview.js"></script>
<body>
<div id="rr" style="width:500px;height:250px;border:1px solid #ccc;position:relative">
     <table id="dg" style="width:500px;height:250px" sortorder="desc" title="DataGrid - Expand Row" singleselect="true" fit="true"  fitcolumns="true">  
    <thead>  
        <tr>  
            <th field="itemid" width="60">Name</th>  
            <th field="productid" width="80">Product</th>  
            <th field="listprice" align="right" width="70">Unit</th>  
            <th field="unitcost" align="right" width="70">Email</th>  
            <th field="status" width="50" align="center">Status</th>  
        </tr>  
    </thead> 
          <tbody>  
        <tr>  
            <td>Foo</td><td>Bar</td><td>111222333</td><td>foo.bar@gmail.com</td><td>ok</td> 
        </tr>  
        </tbody>  
</table>  
</div>  
    
</body>

JavaScript

$(function(){
    
    var expandedRows = new Array();
    
      buildTable();
      setResizable();
 
    
     $('#dg').datagrid('expandRow',0);
    
    //Calling Expand Row programmatically, the detail view does not occupy the entire size
   //  $('#dg').datagrid('expandRow',0);
     // $('#dg').datagrid('collapseRow',0);
    
})


function buildTable(){
    
  //  function buildDataGrid(){
  $('#dg').datagrid({  
    view: detailview,  
    detailFormatter:function(index,row){  
        return '<div id="ddv-' + index + '" style="padding:5px 0"></div>';  
    },  
    onExpandRow: function(index,row){  
        $('#ddv-'+index).datagrid({ 
                        fit:true,
                        fitColumns:true,
                        singleSelect:true,
                        rownumbers:true,
                        columns:[[
                            {field:'orderid',title:'Order ID'},
                            {field:'quantity',title:'Quantity'}
                        ]], 
                     data:[{orderid:'1',quantity:'3'},{orderid:'2',quantity:'100'}],
                        onLoadSuccess:function(){
                            setTimeout(function(){
                                $('#dg').datagrid('fixDetailRowHeight',index);
                            },0);
                        }
                    });
        $('#dg').datagrid('fixDetailRowHeight',index);  
    },
      
   onCollapseRow: function(index,row){
       //alert("Collapsing index :"+index);
   }
});
    
}  


function setResizable(){
    
     $('#rr').resizable({  
    maxWidth:800,  
    maxHeight:600,
       onStopResize:function(){
           var height = $('#rr').height();
           var width = $('#rr').width();
           
      $('#dg').datagrid('resize');
   }
       
   });    
     
}