如何在YII bootstrap.widgets.TbGridView中添加下拉列表

时间:2013-06-15 05:26:15

标签: gridview yii updates

如何在YII bootstrap.widgets.TbGridView中添加下拉列表。

$this->widget('bootstrap.widgets.TbGridView',  array(
    'id'=>'customer-grid',
    'type'=>'striped bordered condensed',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'surname',
        'name',
        'middlename',
        'dateOfBirth',
        array(
            'class'=>'bootstrap.widgets.TbButtonColumn',
            'template'=>'{add}',
            'buttons'=>array(
                'add' => array(
                    'label'=>'list-box',
                    'icon'=>'plus',
                    'url'=>'Yii::app()->createUrl("url")',
                    'options'=>array(
                        'class'=>'btn btn-small',
                    ),
                ),
            ),
        ),
    ),
));

我只想在此处添加下拉列表而不是“添加”按钮。有谁能够帮我。我是YII的新手

提前致谢

1 个答案:

答案 0 :(得分:0)

试试这个,而不是将下拉列入tbbutton列,将其放入列中,如图所示

在模型中包含一个函数

public function getDropdown()
{
    $values = array(
        1 => 'value1',
        2 => 'value2',

    );
    return CHtml::dropDownlist('$model',variable,$values, array(
        'class'     => 'values',
        'data-id'   => $this->id,
    ));
}

在cgrid视图中将函数调用为

'columns'=>array(
 'surname',
    'name',
    'middlename',
    'dateOfBirth',
     array(
            'name'  => 'Value',
            'type'  => 'raw',
            'value' => '$data->Dropdown',
        ),
),
相关问题