Zhumpex Zhumpex - 5 months ago 116
jQuery Question

Master / Detail Table With JQuery Easyui

I have two table like this example. (Created with easyui datagrid)

enter image description here

I want displaying detail from table master when I click on the list of table master. I have read in easyui site, but I don't find that I want. I only find tutorial how create it with flexigrid. Can anyone give me an example to do that with easyui datagrid ?

Answer

Create javascript function

function showDetail(){
        var row = $('#dg').datagrid('getSelected');
        if (row){
            $('#dgd').datagrid('reload',row);
            url = 'detail.php?id='+row.id;
        }
    }

And detail.php

<?php
    $id = $_REQUEST['id'];

    $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
    $offset = ($page-1)*$rows;
    $result = array();

    include 'conn.php'; // Connection to database

    $rs = mysql_query("select count(*) from product WHERE id='$id'");
    $row = mysql_fetch_row($rs);
    $result["total"] = $row[0];
    $rs = mysql_query("select * from product WHERE id='$id' limit $offset,$rows");

    $items = array();
    while($row = mysql_fetch_object($rs)){
        array_push($items, $row);
    }
    $result["rows"] = $items;

    echo json_encode($result);
?>
Comments