Filter For Gridview

Hey,

i have a problem with the filter of my grid view. I try to set the filter attribute of my "bootstrap.widgets.TbGridView" like the folling:


$this->widget('bootstrap.widgets.TbGridView', array(

			'dataProvider' => $dataProvider,

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

but i become the following error:

CActiveDataProvider and its behaviors do not have a method or closure named "getValidators".

The $model->search() is the custom model created from the gii Tool.

Maybey i have to change the "CActiveDataProvider" in the $model->search() method?




		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));



The search method normally returns a data provider. I think you just want:




'filter'=>$model,



Ok, now there is a row placed with textinput fields placed at the head of the table. But the filter doesen’t work. If i type something in the textinput fields and press enter than nothing happens. All rows are shown like before.

This is my action:




public function actionMyAction()

{	

	$model=new MyModel('search');

	$model->unsetAttributes();  

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

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

		

	$dataProvider = new CActiveDataProvider('MyModel', array( 

											'criteria' => array(

											'condition' => 'somevalue = :somevalue', 

											'params' => array(':somevalue'=> 1,),),

											'pagination'=> array('pageSize' => 5,),));

									

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

		'dataProvider'=>$dataProvider,

		'model' => $model

	));

}



and this is the view with the "bootstrap.widgets.TbGridView":




$this->widget('bootstrap.widgets.TbGridView', array(

			'dataProvider' => $dataProvider,

			'filter' => $model,

			'template' => "{items}",

			'columns' => array(

				array(

					'name' => 'value1',

					'header' => 'value1',

				),

				array(

					'name' => 'value2',

					'header' => 'value2',

				),

			),

		)

	); 




You need to show your model rules and search method.

Edit:

Your data provider should be coming from the search method.




$dataProvider = $model->search();



Ok, i use an modified code in the last post, so here is the real code:

action:




	public function actionPublicLists()

	{	

		$model=new WordList('search');

		$model->unsetAttributes();  

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

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

			

		$dataProvider = new CActiveDataProvider('Wordlist', array( 

														 'criteria' => array(

															'condition' => 'public = :public', 

															'params' => array(':public'=> 1,),),

														 'pagination'=> array('pageSize' => 5,),));

										

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

			'dataProvider'=>$dataProvider,

			'model' => $model

		));

			

	}



view:




<?php 

$this->widget('bootstrap.widgets.TbGridView', array(

			'dataProvider' => $dataProvider,

			'filter' => $model,

			'template' => "{items}",

			'columns' => array(

				array(

					'name' => 'title',

					'header' => 'Title',

				),

				array(

					'name' => 'language1',

					'header' => 'Language 1',

				),

				array(

					'name' => 'language2',

					'header' => 'Language 2',

				),

				array(

					'name' => 'user',

					'header' => 'User',

				),

				array(

					'class' => 'CLinkColumn',

					'label' => 'Vocabulary List',

					'url' => 'index.php',

				),

				array(

					'class' => 'CLinkColumn',

					'label' => 'Subscripe',

					'url' => 'index.php',

				),

			),

		)

	); 

?>



model search:




	public function search()

	{

		// @todo Please modify the following code to remove attributes that should not be searched.


		$criteria=new CDbCriteria;


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

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

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

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

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

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


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}



model rules:




	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			['title, language1, language2, public', 'required'],

			['title', 'length', 'max' => 255],

			['language1, language2', 'length', 'max' => 128],

			//['user', 'length', 'max' => 10],

			// The following rule is used by search().

			// @todo Please remove those attributes that should not be searched.

			array('id, title, language1, language2, user, public', 'safe', 'on'=>'search'),

		);

	}



Edit: Ok, the problem is that i only want to filter through the rows which are public (public = 1).

Your code is confusing me now, but to customise the search, use a pattern like this:




$model=new WordList('search');

$model->unsetAttributes();


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

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


$model->public = 1; // Override user defined value here


$dataProvider = $model->search();



Thank you, that was exactly what i search for