Frage

I'm stuck with a problem on my CGridView. I want to make columns clickable, so that it redirects to a new page.

My problem is that I try to use selectionChange, and Yii throws an exception telling Property "CDataColumn.selectionChanged" is not defined.

Here is my code:

<?php   $this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider'=>$dataProvider,
        'columns'=>array(
            array('header'=>'First Name'
                , 'type'=>'raw'
                , 'htmlOptions'=>array('style'=>'cursor: pointer;')
                , 'name'=>'first_name'
                , 'sortable'=>true
                , 'selectionChanged'=>'function(id){window.location=\'CHtml::link($data["first_name"],Yii::app()->createUrl("/athlete/view", array("id"=>$data["id"])))\'}'),
            array('header'=>'Last Name'
                , 'htmlOptions'=>array('style'=>'cursor: pointer;')
                , 'type'=>'raw'
                , 'name'=>'last_name'
                , 'selectionChanged'=>'function(id){window.location=\'CHtml::link($data["first_name"],Yii::app()->createUrl("/athlete/view", array("id"=>$data["id"])))\'}'),
            array('header'=>'Date of Birth'
                , 'value'=>'Controller::date($data["dob"])'
                , 'htmlOptions'=>array('width'=>'90px', 'style'=>'cursor: pointer;')
                , 'name'=>'dob'
                , 'selectionChanged'=>'function(id){window.location=\'CHtml::link($data["first_name"],Yii::app()->createUrl("/athlete/view", array("id"=>$data["id"])))\'}'),
            array(
                'header'=>'Edit'
                ,'class'=>'CButtonColumn'
                ,'template'=>'{update}'
                , 'updateButtonUrl'=>'Yii::app()->createUrl("/athlete/update", array("id"=>$data["id"]))'
            ),
        ),
        'pagerCssClass'=>'clist-pager',
        'pager'=>array('header'=>''),
    ));
?>

So, could you help me figure out why this exception is thrown, and fix it?

War es hilfreich?

Lösung

You cannot define selectionChanged on the columns themselves, that property only exists on the grid view:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'selectionChanged'=>'function(id) { /* ... */ }',
    // columns, etc
);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top