CGridViewWii フレームワークのウィジェットで特定の列データを表示/非表示にすることを検討しています。
私CButtonColumnは3つのボタンを含むを持っています。ただし、特定の条件で、特定の行に別のものを表示したい。特定の行に表示されるものを決定する3つの異なる条件があります。
以下は、私がやりたいことを示しています。
| 1 | Title A | [hide][view][update] <-- if (condition == 'a')
| 2 | Title B | [hide][view][update] <-- if (condition == 'a')
| 3 | Title C | display text or link or button <-- if (condition == 'b')
| 4 | Title D | display alternative buttons <-- if (condition == 'c')
ここで取るべき最善のアプローチは何ですか?
'visible'=> $model->processingStatus != "processed"列全体が削除されるため、列には使用できません。代わりに各行をターゲットにする必要があります。
'visible'個々のボタンごとにパラメーターを使用する必要がありますか? 以下のコメントアウトされたコードを使用してこれを試しましたが、ページが壊れます。参考までに: CButtonColumn 自体で「visible」パラメーターを試してみましたが、必要なものではありません。さらに、どの行のステータスが読み取られているのかわからない。
または、コントローラーに関数を追加する必要がありますか? if/else ステートメントを実行して、表示される内容を返します。これはどのように機能しますか?
これが私のコードです:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'my-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'myid',
'header'=>'ID',
),
'Title',
array(
'class'=>'CButtonColumn',
'visible'=> $model->status != "done",
'template'=>'{hide}{view}{update}',
'buttons'=>array(
'hide'=>array(
'label'=>'Hide', //Text label of the button.
'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/bulb-off.png' //Image URL of the button.
//'click'=>'function(){alert("Toggle Hide!");}', //A JS function to be invoked when the button is clicked.
//'options'=>array(), //HTML options for the button tag.
//'url'=>'javascript:void(0)', //A PHP expression for generating the URL of the button.
//'visible'=> $model->status == "done", //A PHP expression for determining whether the button is visible.
),
'view'=>array(
//Text label of the button.
'label'=>'View',
//Image URL of the button.
'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/view-record.png'
),
'update'=>array(
'label'=>'Update/Edit',
'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/edit-pencil.png',
'url'=>'Yii::app()->createUrl("metadataandchapters/create?bookid=" . $data->bookid)',
)
)
)
)
)); ?>
私がここで十分な意味を持っていることを願っています!