Yii CGridView filtering is working but search not working so what would be miss , can u help me to sort out this issue my code attach bellow
#########grid.php ######################
<?php
//grid ajax search
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('coupon-grid', {
data: $(this).serialize()
});
return false;
});
");
//set page size for data provider
$dp = $coupons->search();
$dp->pagination->pageSize = 25;
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'coupon-grid',
'dataProvider'=>$dp,
'columns'=>array(
array(
'name'=>'AdvertisementName',
'type'=>'raw',
'value'=>'CHtml::link(CHtml::encode($data->offer_title), array("create", "id"=>$data->id))',
),
array(
'name'=>'store_name',
'value'=>'$data->store_name',
),
array(
'name'=>'Vendor',
'value'=>'$data->vendor->description',
),
'exp_date:text:Expiration Date',
/*array(
'name'=>'CreatedBy',
'value'=>'$data->user->name',
), */
'status:text:Status'
),
'cssFile'=>false
));
?>
index.php
<script type="text/javascript">
$(function() {
$("#Coupon_created_date").datepicker({dateFormat: 'yy-mm-dd'});
});
</script>
<div>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td class="tab-content-left ver-bg"></td>
<td class="tab-content">
<?php
$form = $this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl($this->route),
'method' => 'get',
));
?>
<div class="row container-1">
<div class="inner-frame">
<table cellpadding="0" class="tbl-form" cellspacing="0" border="0" width="100%">
<tr>
<td width="160" class="bold-text" >Offer Title:</td>
<td width="200"><?php echo CHtml::activeTextField($coupons, 'offer_title', array('class' => 'txt-common')) ?></td>
<td width="35"></td>
<td width="160" class="bold-text" >Status:</td>
<td><?php echo CHtml::activeTextField($coupons, 'status', array('class' => 'txt-common')) ?></td>
</tr>
<tr>
<td class="bold-text" >Category:</td>
<td ><?php echo CHtml::dropDownList('catogary_id', $categoryId, CHtml::listData($catogaries, 'id', 'name'), array('empty' => '- - Select - -')); ?></td>
<td ></td>
<td class="bold-text" >Created By:</td>
<td><?php echo CHtml::activeDropDownList($coupons, 'created_by', CHtml::listData($users, 'id', 'name'), array('empty' => '- - Select - -')); ?></td>
</tr>
<tr class="last">
<td class="bold-text" >Created Date:</td>
<td ><?php echo CHtml::activeTextField($coupons, 'created_date', array('class' => 'txt-common')) ?></td>
<td ></td>
<td class="bold-text">Store Name</td>
<td><?php echo CHtml::activeTextField($coupons, 'store_name', array('class' => 'txt-common')) ?></td>
</tr>
</table>
</div>
</div>
<div class="row">
<?php echo CHtml::submitButton('Search', array('id' => 'search_btn', 'class' => 'btn hor-bg', 'name' => 'Search')); ?>
<?php echo CHtml::submitButton('Clear Search Fields', array('id' => 'search_clear_btn', 'class' => 'btn hor-bg', 'name' => 'Clear')); ?>
</div>
<?php $this->endWidget(); ?>
<div class="row">
<div class="grid-title">
<div class="inner-bdr"> <span class="float-left bold-text">Advertisement List</span>
<div class="clear-both"></div>
</div>
<div class="grid-bg">
<div class="grid-bg-inner-bdr">
<?php echo $this->renderPartial('grid', array('coupons' => $coupons)); ?>
</div>
</div>
</div>
</div>
<div class="">
<input type="button" onclick="goTo('<?php echo Yii::app()->params['hostname'] . '/index.php/admin/coupon/create' ?>')" class="btn hor-bg" value="Add New Advertisement" />
<input type="button" onclick="goTo('<?php echo Yii::app()->params['hostname'] . '/index.php/admin/coupon/review' ?>')" class="btn hor-bg" value="Edit Advertisements" />
</div>
</td>
<td class="tab-content-right ver-bg"></td>
</tr>
</table>
</div>
####### model search action ##########################
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$sort = new CSort();
$sort->attributes = array('AdvertisementName'=>array('asc'=>'offer_title', 'desc'=>'offer_title desc',),
'store_name'=>array('asc'=>'store_name', 'desc'=>'store_name desc',),
'exp_date'=>array('asc'=>'exp_date', 'desc'=>'exp_date desc',),
'status'=>array('asc'=>'t.status', 'desc'=>'t.status desc',),
'CreatedBy'=>array('asc'=>'user.name', 'desc'=>'user.name desc',),
'Vendor'=>array('asc'=>'vendor.description', 'desc'=>'vendor.description desc',),
);
$criteria = new CDbCriteria;
$criteria->with = array('vendor', 'user');
if (!empty($this->subCategoryIdsAr) && is_array($this->subCategoryIdsAr)) {
foreach ($this->subCategoryIdsAr as $subcategoryId) {
$criteria->compare('sub_category_id', $subcategoryId->id, true, 'OR');
}
}
$criteria->compare('id', $this->id, true);
$criteria->compare('t.created_date', $this->created_date, true);
$criteria->compare('offer_title', $this->offer_title, true);
$criteria->compare('t.created_by', $this->created_by, true);
$criteria->compare('t.status', $this->status, true);
$criteria->compare('t.store_name', $this->store_name, true);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
'sort'=>$sort,
));
}
######## IndexAction,php #########################
<?php
/**
* LoginAction class file
*
* @author Gayan
* @copyright Copyright© 2011 SoNET Systems
*/
/**
* Used to hanle login functinality
*
* @package am.admin.Dashboard
*/
class IndexAction extends CAction {
public function run() {
$controller = $this->getController();
$categoryId = '';
//create models for view
$coupons = new Coupon();
$users = User::model()->findAll();
$catogaries = Category::model()->findAll();
foreach ($catogaries as $category) {
$category->name = ucfirst($category->name);
}
if (isset($_POST['Clear'])) {
unset($_POST);
Yii::app()->user->setState('searchFields', '');
}
if (isset($_POST['Coupon'])) {
if (isset($_POST['catogary_id']) && !empty($_POST['catogary_id']))
$categoryId = $_POST['catogary_id'];
$coupons->getSubCategories((int) $categoryId);
$coupons->attributes = $_POST['Coupon'];
$coupons->setStateAttributes(); //set searching fields to state for ajax pagination
}
//if (Yii::app()->request->isAjaxRequest) {
$coupons->attributes = Yii::app()->user->getState('searchFields');
//}
$params = array(
'coupons'=>$coupons,
'users'=>$users,
'catogaries'=>$catogaries,
'categoryId'=>$categoryId
);
$controller->render('index', $params);
}
}
plz help me to solve this issue?