Joe
Joe

Reputation: 2591

Button column on CGridView with CSqlDataProvider as provider?

I'm using CSqlDataProvider to provide data for CGridView. It all runs fine until I want to add CButtonColumn column. It resultsl in error:

Trying to get property of non-object 

and in the stack there

echo $this->displayExtendedSummary && !empty($this->extendedSummary['columns']) 
        ? $this->parseColumnValue($column, $row) : $column->renderDataCell($row);

at file:

    c:\...\yii\framework\zii\widgets\grid\CButtonColumn.php(316)

Any ideas how to deal with that?

EDIT: Provider:

$provider = new CSqlDataProvider($query, array(
        'totalItemCount' => $countRes,
        'db' => $this->db,
        'keyField' => 'idCall',
        'params' => $params,
        'pagination' => array(
            'pageSize' => 25,
        ),
        'sort' => array(
            'attributes' => array(
                'idCall, idTime',
            ),
        ),
    ));

In view:

<?php $this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'call-history-grid',
'type' => 'striped condensed',
'template' => '{pager}{items}{summary}',
'htmlOptions' => array('style' => 'font-size: 0.75em'),
'dataProvider'=>$model->getInviteCallList(),
'columns'=>array(
    array(
        'header' => '#',
        'value' => '$data["idCall"]',
        'visible' => 'Yii::app()->user->superuser',
    ),
    array(
        'header' => 'Data',
        'value' => '$data["callDateTime"]',
    ),
                    array(
        'class'=>'zii.widgets.grid.CButtonColumn',
    ),

I use here bootstrap gridview but if I switch to regular CGridView - problem is the same.

Upvotes: 0

Views: 2741

Answers (1)

soju
soju

Reputation: 25312

Well, unlike CActiveDataProvider, CSqlDataProvider doesn't have all the needed information to support default CButtonColumn buttons.

CActiveDataProvider will provide object, but CSqlDataProvider will provide array, and CButtonColumn works with objects, that's why you get "Trying to get property of non-object" error message...

You should define buttons url, e.g. :

array(
  'class'=>'zii.widgets.grid.CButtonColumn',
  'viewButtonUrl'=>'Yii::app()->createUrl("/mycontroller/view", array("id"=>$data["idCall"]))',
  'updateButtonUrl'=>'Yii::app()->createUrl("/mycontroller/update", array("id"=>$data["idCall"]))',
  'deleteButtonUrl'=>'Yii::app()->createUrl("/mycontroller/delete", array("id"=>$data["idCall"]))',
),

Upvotes: 3

Related Questions