Gridview In Another View.

Hello,

I was wondering if was possible, to use the Gridview with the data from a model. in a view without that corresponding model.

In fact I already tried it though. but all I can’t get to work is the search function (not the advanced search)

Although the filtering works.

ALl information would be welcome, (I use the extension of Bootstrap, But I doubt this would make much difference)

Thx for your time : )

in order to work the searching function you should set the filter property of the gridview to the model that provides data.

Now this is the code I use in my Gridview:


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

	'id'=>'repairs-grid',

	'dataProvider'=> Repairs::model()->search(),

	'filter'=>  Repairs::model(),

	'columns'=>array(

Now the gridview does show all the data it should, only the search boxes that each column has. that’s where my problem lies. I think they don’t works cause they don’t reach the DBcriteria. is there anny way to fix this?

first of all you must create the object for Repairs model under search scenario in your action and then pass the model to your view like this




//1. in action

actionGrid()

{

$model= new Repairs('search');

$this->render('myView',array('model'=>$model);

}


//2. in view

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

'id' => 'repairs-grid' ,

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

'filter' =>$model,

'columns' =>array (

 ....

)

));



Thx for you fast responses, Due to illness I haven’t been able to work on my project for quite some time. but I’m all better now.

I have a few questions.

I’ve tried to use the actionGrid, if I’m correct this is supposed to be in my RepairController right?

Do I also have to add something in my model cause of this?

Then also, the $this->render(‘myview’), I don’t know what view to put in there, cause the view I want it in, does not belong to this model.

Note that, the search and all does work in the view with the corresponding model.

use like this




$this->render('/repairs/yourView',array('model'=>$model));



Note: repairs is a model name and yourView is your view file to render grid starting with slash(/) is must