Yii 1.1: Filter / Search with CListView


This is what I did. Its the EASIEST solution that I know of. I just reused the advanced search done in CGridView.

In my controller file

public function actionIndex()
    $model=new Blogs('search');
    $model->unsetAttributes();  // clear any default values
    //send model object for search

In my view file (namely my index file)

    array('label'=>'Create Blogs', 'url'=>array('create')),
    array('label'=>'Search Blogs', 'url'=>array('admin')),
Yii::app()->clientScript->registerScript('search', "
    return false;
$('.search-form form').submit(function(){
    $.fn.yiiListView.update('blogslistview', { 
        //this entire js section is taken from admin.php. w/only this line diff
        data: $(this).serialize()
    return false;
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php  $this->renderPartial('_search',array(
)); ?>
<?php $this->widget('zii.widgets.CListView', array(
    'id'=>'blogslistview',       // must have id corresponding to js above

Total 9 comments

#19130 report it
clouds at 2015/03/26 10:58am
Thank you!!

the right wiki at the right time

#18981 report it
Carlos Ramos at 2015/02/17 02:08pm

Just tried it out on a list view and worked like a charm :D. I was forgetting to use yiiListView instead of yiiGridView on the javascript. Saved me hours of headaches for such an obvious mistake.

#16897 report it
amanation at 2014/04/10 04:09pm
Thanks for this

You just saved me some hours. Thank you

#13610 report it
darsa at 2013/06/11 06:52am
Nice tutorial

Thank you! I have some other requirements , I want to add a filter to the search result which is shown in the list view after searching, Like grid view search. Thank you in advance

#12653 report it
ngii at 2013/04/04 04:05am
Really Works

This one works after trying other solutions.

#12292 report it
VincentBz at 2013/03/11 03:34pm
Works great!

Thank you very much. I am using this and it does work.

#10391 report it
nirmalroka at 2012/10/25 04:52am
Nice tutorial, thank you


#7085 report it
Yureshwar Ravuri at 2012/02/23 04:15am
Good tutorial

Served my requirement.

#6606 report it
jmariani at 2012/01/20 03:06pm

Thank you!

Leave a comment

Please to leave your comment.

Write new article