I'm trying to add in one column of the CGridView a filter with select2 extension following this answer but does not work.
My code:
In view 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',
),
)));
In vehiculos.php Model
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(
),
));
}
Display Error CException:
Vehiculos and its behaviors do not have a method or closure named "widget".
No need to fetch the widget from controller method
In the gridview column
I have created a class extending the CDataColumn to add a filter to the column:
And then you add this column to your cgridview: