dqf42223
dqf42223
2013-05-23 09:59
浏览 57
已采纳

Yii CGridView:selectionChanged未定义

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douyun3799
    douyun3799 2013-05-23 10:03
    已采纳

    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
    );
    
    点赞 评论

相关推荐