Reputation: 439
I have just started to work on Yii and facing some issues on CGridView..
the ajax filter is not working in the grid view.. when i chceked the console i see that no ajax request is sent.
this is my view (admin.php)
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#user-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'email_id',
'name',
'user_type',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
model file(User.php)
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('email_id',$this->email_id,true);
$criteria->compare('name',$this->name,true);
//$criteria->compare('password',$this->password,true);
$criteria->compare('user_type',$this->user_type);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array('pageSize'=>3),
));
}
and inside rules()
array('id, email_id, name, user_type', 'safe', 'on'=>'search'),
in controller file (UserController.php)
public function actionAdmin()
{
$model=new User('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['User']))
$model->attributes=$_GET['User'];
$this->render('admin',array(
'model'=>$model,
));
}
Also advanced search form does not open on clicking 'Advanced Search'.. I have searched a number of threads related to it but its not helping.. pls help me in identifying the problem.. Regards Leo
Upvotes: 2
Views: 4898
Reputation: 61
I had same error some time ago. It was because I had included my own jquery declaration at the bottom of my page and there was a conflict with YII auto script management, that includes jquery declaration in the head of the page.
You should be able to see that by looking at the generated source code of your page...
Good luck
Upvotes: 0
Reputation: 398
Debuging tip: If something depending on the JavaScript is not working, 99% you're getting a JavaScript error which terminates the rest of JavaScript.
Upvotes: 2