Question

I'm a newbie to yii and have difficulty on using subform and gridview. I want to create a simple accounting journal with these tables:

t_journal
---------
id_journal
dates

t_journal_detail
----------------
id
id_journal
journal_code
journal_name
desc
debit_value
credit_value

I'd like to use two gridview for this, one for t_journal, and one for t_journal_detail which is inside t_journal gridview, just like below:

$this->widget( 'bootstrap.widgets.TbGridView', array(
    'id'             => 'jurnal-harian-grid',
    'template'       => "<div>{pager}</div><div style='float:left;'>{summary}</div><div class='clear'>&nbsp;</div>\n{items}\n<div>{pager}</div><div style='float:left;'>{summary}</div><div class='clear'>&nbsp;</div><br/>",
    'dataProvider'   => $model->search(),
    'columns'        => array(
        array(
            'name'   => 'id_journal',
            'header' => 'ID',
        ),
        array(
            'name'   => 'dates',
            'header' => 'Date',
            'value'  => 'date("d-m-Y",strtotime($data["dates"]))',
        ),
        array(
            'header' => 'Details',
            'value'  => $this->renderPartial('_subjurnal', array("modelDetail"=>$modelDetail), true),
        ),
    ),
) );

inside _subjurnal.php, I insert a one column table with word "Testing"

<table border="0">
    <tr>
        <td>Testing</td>
    </tr>
</table>

Is that the right way to insert another subform or subpage inside gridview? Because I got an error on every row of journal gridview:

Parse error: syntax error, unexpected '<' in D:\xampp\htdocs\cvsunrise\yii\framework\base\CComponent.php(616) : eval()'d code on line 1

What is the right way to do that? A help for this would be much appreciated.

Was it helpful?

Solution

"modelDetail"=>$modelDetail its not defined i assume. Actually it should work with few corrections:

  1. column type - use 'type'=>'raw'

  2. If you want to use external variable in gridview you need to import it. Also better to make this with function:

'value' => function ($data,$row) use $modelDetail {$this->renderPartial('_subjurnal', array("modelDetail"=>$modelDetail), true);},

Also avoid double loading of js scripts.

OTHER TIPS

The @ineersa answer it's a correct solution.

after that, if you will have a javascript problem, try putting this line al last of "inside_journal.php" view:

    <?php Yii::app()->getClientScript()->scriptMap=array('jquery.js'=>false, 'jquery.ui.js'=>false); ?>

In the array() put the libs that are charging twice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top