2

我在一个网格中显示了两个表(通过LEFT JOIN),我想知道有没有办法为同一个网格中的两个表实现内联编辑功能?

即:当主网格表更新时:

onSuccess { table_name, {column1=value1,column2=value2,..}}

不一定高于场景 - 我在这里寻找想法和逻辑......

我知道西装有setAfterCrudAction功能jqGridPHP,但从整个西装中我只需要这个功能......所以我正在寻求在你的帮助下自己实现它

任何想法表示赞赏,谢谢

4

1 回答 1

0

示例显示了在使用连接时如何更新字段(检查“PHP Grid”选项卡,顺便说一下 jqgrid-php是免费的):

<?php

class jqOperBasic extends jqGrid
{
    protected function init()
    {
        $this->table = 'tbl_order_item';

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

        #Set columns
        $this->cols = array(

            'item_id' => array('label' => 'ID',
                'db' => 'i.id',
                'width' => 10,
                'align' => 'center',
                'formatter' => 'integer',
            ),

            'order_id' => array('label' => 'Order id',
                'db' => 'i.order_id',
                'width' => 15,
                'align' => 'center',
                'formatter' => 'integer',
            ),

            'name' => array('label' => 'Book name',
                'db' => 'b.name',
                'width' => 30,
                'editable' => true,
                'editrules' => array('required' => true),
            ),

            'price' => array('label' => 'Price',
                'db' => 'i.price',
                'width' => 15,
                'align' => 'center',
                'formatter' => 'integer',
                'editable' => true,
                'editrules' => array('required' => true,
                    'integer' => true,
                    'minValue' => 1,
                    'maxValue' => 3000
                ),
            ),
        );

        #Set nav
        $this->nav = array('edit' => true, 'edittext' => 'Edit');
    }

    #Save columns to different tables
    protected function opEdit($id, $upd)
    {
        #Server-side validation
        if(strlen($upd['name']) < 5)
        {
            #Just throw the exception anywhere inside the oper functions to stop execution and display error
            throw new jqGrid_Exception('The book name is too short!');
        }

        #Get editing row
        $result = $this->DB->query('SELECT * FROM tbl_order_item WHERE id=' . intval($id));
        $row = $this->DB->fetch($result);

        #Save book name to books table
        $this->DB->update('tbl_books', array('name' => $upd['name']), array('id' => $row['book_id']));
        unset($upd['name']);

        #Save other vars to items table
        $this->DB->update('tbl_order_item', $upd, array('id' => $id));
    }
}
于 2013-02-08T16:48:00.150 回答