Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery EasyUI DataGrid - Expanding Rows to Show Details

jQuery EasyUI DataGrid - Expanding Rows to Show Details

The datagrid can change its view to display different effects. With the detail view, the datagrid can display an expand button ("+" or "-") on the left side of the data row. Users can expand a row to show additional detail information.

Step 1: Create the DataGrid



    

        

            

                

                

                

                

                

            

        

    
Item IDProduct IDList PriceUnit CostStatus

Step 2: Set the detail view for the DataGrid

To use the detail view, remember to reference the view script file in the head of the page.







$('#dg').datagrid({

    view: detailview,

    detailFormatter:function(index,row){

        return '
';     },     onExpandRow: function(index,row){         var ddv = $(this).datagrid('getRowDetail',index).find('div.ddv');         ddv.panel({             border:false,             cache:false,             href:'datagrid21_getdetail.php?itemid='+row.itemid,             onLoad:function(){                 $('#dg').datagrid('fixDetailRowHeight',index);             }         });         $('#dg').datagrid('fixDetailRowHeight',index);     } });

We define the 'detailFormatter' function to tell the datagrid how to render the detail view. In this case, we return a simple '

' element, which will act as the container for the detail content. Note that the detail information is empty. When the user clicks the expand button ('+'), the onExpandRow event is triggered. So we can write some code to load the detail content via ajax. Finally, we call the 'fixDetailRowHeight' method to fix the row height when the detail content is loaded.

Step 3: Server-side code

datagrid21_getdetail.php



<?php

    include_once 'conn.php';



    $itemid = mysql_real_escape_string($_REQUEST['itemid']);



    $rs = mysql_query("select * from item where itemid='$itemid'");

    $item = mysql_fetch_array($rs);

?>





    

        

        

        

        

        

    

    

        

        

        

        

    

    

        

        

    
            <?php                 $aa = explode('-',$itemid);                 $serno = $aa[1];                 $img = "images/shirt$serno.gif";                 echo "";             ?>         Item ID: <?php echo $item['itemid'];?>Product ID:<?php echo $item['productid'];?>
List Price: <?php echo $item['listprice'];?>Unit Cost:<?php echo $item['unitcost'];?>
Attribute: <?php echo $item['attr1'];?>

Download the jQuery EasyUI example

jeasyui-datagrid-datagrid21.zip