Yii CListView custom ajax search fileter

We can make a custom search on CListView listing page with pagination.

Following steps, we are making search on left side filters but cList view results will filter on this ajax search :

1 search form   2. js script function with update Clistview grid widget 3. controller action as per values and render view.

1 View page :

– it can be index.php for listing, just add id of your choice to you listing widget

<?php $this->widget(‘zii.widgets.CListView’, array(
)); ?>

2. Js script part , from where you push to start ajax, you can call it on submit button or on any link etc.

Yii::app()->clientScript->registerScript(‘searchlist’, ”

$.fn.yiiListView.update(‘slistview’, {
data: $(‘#search’).serialize()+’&isAjaxRequest=1′
return false;

3. Controller submit action handler and check if request is ajax

public function actionIndex()
$cid=(isset($_POST[‘cat’]) && is_numeric($_POST[‘cat’])) ? trim($_POST[‘cat’])  : ”;

$criteria=new CDbCriteria;

$criteria->join=’JOIN product_category pc ON pc.pid=t.id’;



if(isset($_GET[‘isAjaxRequest’]) && $_GET[‘isAjaxRequest’]==’1′) {
$cid=(isset($_GET[‘cat’]) && is_numeric($_GET[‘cat’])) ? trim($_GET[‘cat’])  : ”;

$criteria->join=’JOIN product_category pc ON pc.pid=t.id ‘;

$dataProvider=new CActiveDataProvider(‘Product’,array(‘criteria’=>$criteria));






contact us