如何在 Yii 上的 CGridView 中添加 select2 扩展作为过滤器 [英] How to add select2 extension as filter in CGridView on Yii
本文介绍了如何在 Yii 上的 CGridView 中添加 select2 扩展作为过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在 CGridView 的一列中添加一个带有 select2 扩展名的过滤器 answer 但不起作用.
I'm trying to add in one column of the CGridView a filter with select2 extension following this answer but does not work.
我的代码:
查看vehiculos/admin.php
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'vehiculos-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'placa',
array(
'name'=>'asociado_id',
'value'=>'Vehiculos::model()->getListNombreCompleto()',
'type'=>'html',
),
'modelo',
'color',
array(
'class'=>'CButtonColumn',
),
)));
在 vehiculos.php 模型中
public function getListNombreCompleto()
{
$nombreCompleto = Contactos::model()->findAll();
$data = array();
foreach ($nombreCompleto as $contacto) {
$data[$contacto->id] = $contacto->nombre;
}
$this->widget('ext.select2.ESelect2',array(
'name'=>'asociado_id',
'data'=>$data,
'htmlOptions'=>array(
),
));
}
显示错误 CException:
Vehiculos and its behaviors do not have a method or closure named "widget".
推荐答案
无需从控制器方法中获取小部件
No need to fetch the widget from controller method
在gridview列中
In the gridview column
array(
'name'=>'asociado_id',
'value'=>'Vehiculos::model()->getListNombreCompleto()',
'filter' => $this->widget('ext.select2.ESelect2',array(
'name'=>'asociado_id',
'data'=>$select2_options,
), true)
),
这篇关于如何在 Yii 上的 CGridView 中添加 select2 扩展作为过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文