Subgrid as grid example.
Пример таблицы в таблице. По просьбе с phpclub.ru.
higrid.net嗨网提供电子表格、在线图形等互联网开发及运营技术,提供相关资料及软件下载,分享奇趣网络时事评论!欢迎访问。


部分内容为俄文,higrid计划翻译一下。敬请期待!

php代码和js代码请点击tab查看。
<?php

class jqMiscSubgrid extends jqGrid
{
    protected function init()
    {
        #Set database table
        $this->table = 'tbl_customer';

        #Set columns
        $this->cols = array(

            'id' => array('label' => 'ID',
                'width' => 10,
                'align' => 'center',
            ),

            'first_name' => array('label' => 'First name',
                'width' => 35,
                'editable' => true,
            ),

            'last_name' => array('label' => 'Last name',
                'width' => 35,
                'editable' => true,
            ),

            'email' => array('label' => 'Email',
                'width' => 30,
                'editable' => true,
            ),

            'phone' => array('label' => 'Phone',
                'width' => 25,
                'align' => 'center',
            ),

            'discount' => array('label' => 'Discount',
                'width' => 15,
                'formatter' => 'numeric',
                'align' => 'center',
            ),
        );
    }

    protected function opRenderSubgrid()
    {
        echo $this->Loader->render('jqMiscSubgrid2', array('customer_id' => $this->input('customer_id')));
        exit;
    }

    protected function opEdit($id, $upd)
    {
        return true;
    }
}
<?php

class jqMiscSubgrid2 extends jqGrid
{
    protected function init()
    {
        $this->options = array('rowNum' => 5, 'width' => 600, 'height' => 110);
        $this->render_extend = '{}';
        $this->render_suffix_col = 'customer_id';

        #Set database table
        $this->table = 'tbl_order_item';

        $this->query = "
			SELECT {fields}
			FROM tbl_order_item oi
				JOIN tbl_order o ON (oi.order_id=o.id)
				JOIN tbl_books b ON (oi.book_id=b.id)
			WHERE {where}
		";

        $this->cols_default = array('align' => 'center');

        #Set columns
        $this->cols = array(

            'id' => array('label' => 'ID',
                'db' => 'oi.id',
                'hidden' => true,
            ),

            'book_id' => array('label' => 'Book ID',
                'db' => 'oi.book_id',
                'width' => 10,
            ),

            'book_name' => array('label' => 'Book name',
                'db' => 'b.name',
                'width' => 40,
                'align' => 'left',
            ),

            'price' => array('label' => 'Price',
                'db' => 'oi.price',
                'width' => 15,
            ),

            'quantity' => array('label' => 'quantity',
                'db' => 'oi.quantity',
                'width' => 12,
            ),
        );

        #Set essential condition
        $this->where[] = 'o.customer_id = ' . intval($this->input['customer_id']);
    }

    #prevent common html rendering
    protected function renderHtml($data)
    {
        return '';
    }
}
<script>
    var opts = {
        subGrid:true,
        subGridRowExpanded:function (subgrid_id, row_id) {
            $('#' + subgrid_id)
                .append('<table id="jqMiscSubgrid2' + row_id + '"></table>')
                .append('<div id="jqMiscSubgrid2' + row_id + '_p"></div>');

            $.ajax({
                url:$(this).getGridParam('url'),
                dataType:'script',
                data:{'oper':'renderSubgrid', 'customer_id':row_id}
            });
        }
    };

    <?= $rendered_grid ?>
</script>