PHPSOFT SOLUTIONS LOGO
  • Home
  • About Us
  • Contact Us
  • Contact Us
  • Blog
  • Online Courses
  • Contact US

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(
‘dataProvider’=>$dataProvider,
‘itemView’=>’_view’,
‘id’=>’slistview’,
)); ?>

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

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

$(‘#search’).submit(function(){
$.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()
{
//print_r($_GET);
$cid=(isset($_POST[‘cat’]) && is_numeric($_POST[‘cat’])) ? trim($_POST[‘cat’])  : ”;
$this->layout=’//layouts/column1′;

$criteria=new CDbCriteria;
$criteria->select=’t.*’;

if(!empty($cid))
{
$criteria->join=’JOIN product_category pc ON pc.pid=t.id’;

$criteria->condition=’pc.cid=’.$cid;

}

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

if($cid)
{
$criteria->join=’JOIN product_category pc ON pc.pid=t.id ‘;
$criteria->condition=’pc.cid=’.$cid;
}
}

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

$this->render(‘index’,array(
‘dataProvider’=>$dataProvider,
));

}

 

 

 
?>

Posted on May 2013
Category: Yii

Categories

  • Blog
  • phonegap
  • PHP Frameworks
  • php-jquery
  • system
  • Wordpress
  • Yii

Post navigation

Previous post

Yii orderable grid

Next post

Install wordpress at your localhost


PHPSOFT SOLUTIONS LOGO

Our mission is to satisfy our customers to the best.Money is the source nowdays, the trust of how we can use your money in the best way is build by us.The core value of php soft solutions is to provide the best service to our customers in a great manner.

Contact

PLOT NO. C157, The Groove, Industrial focal point, Phase7,MOHALI, SAS Nagar, Punjab, 160055

8146501814

contact@phpsoftsolutions.in

Pages Links
  • WordPress
  • Yii
  • PHP Frameworks
  • php-jquery
  • system
  • phonegap

© 2025 PHPSOFT SOLUTIONS