简体   繁体   中英

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.

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, eg :

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"]))',
),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM