I have a grid view that lists contents of a table, table has column author_id
.
Now I'm displaying usernames using relation name column syntax author.username
.
Is it possible to all开发者_StackOverflowow user to type in a username in column filter, with support of CJuiAutoComplete, some examples hints?
My code sample:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->with('author')->search(),
'filter'=>$model,
'columns'=>array(
// ...
array(
'name'=>'author.username',
'filter'=> // ?
),
// ...
),
));
The widget has a 3rd parameter that can be set to true which means that will return a string and will not render the widget CJuiAutoComplete.
widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->with('author')->search(),
'filter'=>$model,
'columns'=>array(
// ...
array(
'name'=>'author.username',
'filter'=> $this->widget('zii.widgets.jui.CJuiAutoComplete', $array_params, true),
),
// ...
),
));
and $array_params can be replaced with similar as following ex :
array(
'name'=>'author_username',
//'model'=>$model,
'attribute'=>'city_eve',
'sourceUrl'=>"/controller/action/",
'options'=>array(
'minLength'=>'2',
),
'htmlOptions'=>array(
'size'=>'36'
),
)
and also you have to put in your model search method some checks :
if($request->getQuery("author_username")){
$criteria->addCondition(author.username=:author_username");
$criteria->params[':author_username'] = $request->getQuery("author_username");
}
精彩评论