开发者

How to include CJuiAutoComplete in a CGridView filter?

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");
        }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜