Hola comunidad
busque pero no encontre
lo que quiero es usando zii.widgets.grid.CGridView
ordenar y buscar por un campo relacionado
osea
si tengo un "Libro" que tiene el campo idAutor
y tengo el "Autor" que tiene su nombre
quiero poder ordenar y buscar por nombre
seguro debe haber algun post sobre esto, pero no lo encuentro
gracias
Page 1 of 1
CGridView ordenar y buscar por campo relacionado
#1
Posted 12 May 2010 - 10:59 AM
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
#2
Posted 12 May 2010 - 11:29 AM
Don't say what you think, think what you say
The problem is communication! Excess of communication!
The problem is communication! Excess of communication!
#3
Posted 13 May 2010 - 06:42 AM
[edit] 2 bis I, 2 bis II
gracias PoL
bien
entre este post http://www.yiiframew...umns#entry44210
y este otro http://www.yiiframew...view#entry45469
lo que hay que hacer es
1) modificar el metodo search() del modelo
2) crear un sort "a medida"
[edit] 2 bis I. compare
[edit] 2 bis II. CActiveDataProvider
3) en admin.php (o la vista que corresponda)
saludos!!!
gracias PoL
bien
entre este post http://www.yiiframew...umns#entry44210
y este otro http://www.yiiframew...view#entry45469
lo que hay que hacer es
1) modificar el metodo search() del modelo
$criteria->with=array('autor');
2) crear un sort "a medida"
$sort = new CSort();
$sort->attributes = array(
// para datos sin relacion
'fecha'=>array(
'asc'=>'t.fecha',
'desc'=>'t.fecha desc',
),
//para datos relacionados
'id_autor'=>array(
'asc'=>'autor.nombre',
'desc'=>'autor.nombre desc',
),
);
[edit] 2 bis I. compare
$criteria->compare('t.fecha',$this->fecha,true);
$criteria->compare('autor.nombre',$this->id_autor,true);
[edit] 2 bis II. CActiveDataProvider
return new CActiveDataProvider('Libros', array(
'criteria'=>$criteria,
'sort'=>$sort,
));
3) en admin.php (o la vista que corresponda)
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'libro-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'fecha',
array('name'=>'id_autor','sortable'=>'true','value'=>'$data->autor->nombre'),
saludos!!!
This post has been edited by Horacio Segura: 13 May 2010 - 08:23 AM
KISS - Keep It Simple Stupid
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
ASAP-As Soon As Possible
http://www.yiiframew...oc/cookbook/71/
http://hmsegura.blogspot.com/
Share this topic:
Page 1 of 1

Help













