Cgridview Filter Doesn't Work

Hi

I think I messed up my Yii app some how.

I’m not able to search for records thru the filter fields (the row just underneath the heading). The ajax loading icon apears but nothing happens.

This happens to all my CGridViews.

Im sure I’ve done something to mess it up, but I have no clue what I’ve done :S

I’ve tried to do a var_dum in Search method, but it seems it never reaches the function.

The standard Advanced Search do work thou.

See attached image.

4231

Capture.PNG

The one thing I’ve done different is to replace my Index action code with Admin action code.

My search js:




Yii::app()->clientScript->registerScript('search', "

$('.search-button').click(function(){

	$('.search-form').toggle();

	return false;

});

$('.search-form form').submit(function(){

	$.fn.yiiGridView.update('user-grid', {

		data: $(this).serialize()

	});

	return false;

});

");



Here is the decleration of CGridView in the same file




<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'user-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		

		'UserName',

		'Password',

		'Active',

		'API',

		'APIKey',


		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>



The search method is standard




	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria = new CDbCriteria;


		$criteria->compare('Id',$this->Id);

		$criteria->compare('UserName',$this->UserName,true);

		$criteria->compare('Password',$this->Password,true);

		$criteria->compare('Active',$this->Active);

		$criteria->compare('API',$this->API);

		$criteria->compare('APIKey',$this->APIKey,true);

		$criteria->compare('LanguageId',$this->LanguageId,true);

		$criteria->compare('Email',$this->Email,true);

		$criteria->compare('Status',$this->Status);

		$criteria->compare('CreatedDateTime',$this->CreatedDateTime,true);

		$criteria->compare('CreatedBy',$this->CreatedBy);

		$criteria->compare('ModifiedDateTime',$this->ModifiedDateTime,true);

		$criteria->compare('ModifiedBy',$this->ModifiedBy);


		$t = new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

		

		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}



Does anyone know where I can start looking?

Is it getting to the controller?

When you instantiate the model are you declaring it as ‘search’ scenario?


$model=new User('search');

Does your model list the searchable attributes in the rules() method? Something like this:


array('username, password, active, api, apikey', 'safe', 'on'=>'search'),

Also… have you tried turning on CWebLogRoute to see what is happening? In config/main.php:


	'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				array(

					'class'=>'CWebLogRoute',

				),

				

			),

		),

I’m doing the same thing. I’ve replaced ma index action code with my admin action code, because I want to have grid laout in index. But filter does not work. Can anyone help, I dont know which parts of code to insert here. It’s sad this guy, topic starter disappeared.

Amy, I created $dataProvider with $dataProvider = new CActiveDataProvider(‘Post’);

So it’s model is in $dataProvider->model, right ?

hi Ride,

in your controller do lik this…




public function actionIndex()

	{

			$dataProvider=new CActiveDataProvider('User',array());

			

		$model=new User('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['User']))

			$model->attributes=$_GET['User'];

		

		

		$this->render('index',array(

			'dataProvider'=>$dataProvider,'model'=>$model,

		));

		

	}



I hope it will work for You, if not if not plz post ur controller action…

I think you need set ajaxUrl in the cgridview because the request is default sending to admin. Try


'ajaxUrl'=>$this->createUrl('controller/index')

in cgridview widget.

Geoide, can you plz specifie the file and the funciton, where this code should be placed ?

I suggest you to use this extension which automatically does that.

Tablesorter

and it’s demo

Is a cgridview property:





$this->widget('zii.widgets.grid.CGridView', array(

    	'dataProvider'=>$dataProvider,

		'ajaxUrl'=>$this->createUrl('controller/index'),

	....

));

[size=2]

Please, tell us if it works.