Search Functionality With Gridview In Yii


I have placed my code below.Please go through and help me where i need modification.

I am trying to implement Search functioanlity.

Initially,i need to pass user value(from a textbox) to database.

and i need to display the result set in Gridview based on search query.

The below code will display grid view and column based search is done.

My view(index.php):


/* @var $this SearchPermDataController */


'Search Perm Data',


?><!-- search-form -->



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

'id' =&gt; 'my-model-grid',

'dataProvider' =&gt; &#036;dataProvider,

'filter' =&gt; &#036;model,

'columns' =&gt; array(






My controller (SearchPermDataController):

public function actionIndex()

{&#036;model = new SearchPermData('search');

&#036;model-&gt;unsetAttributes();  // clear any default values

if (isset(&#036;_GET['SearchPermData'])) {

    &#036;model-&gt;attributes = &#036;_GET['SearchPermData'];


&#036;this-&gt;render('index', array(

    'model' =&gt; &#036;model,



Model (SearchPermData):

public function search()


$criteria=new CDbCriteria;


	return new CActiveDataProvider((&#036;this), array(

	        'criteria' =&gt; &#036;criteria,



Please help me in doing this…

Hi soubhagya, welcome to the forum.

There’s a good sample of that in the “admin” page of the gii-generated CRUD.

And please take a look at this wiki.


I am beginner for yii framework.

Please help me in the below:

i have attached Screenshot of my page:

i don’t want to search from the gridview.

I want to remove textboxes in the gridview and i just wanted to search from the above textbox directly.

do i need to do ajax update for this?



Hi soubhagya,

Did you read my reply to your first post?

Gii-generated admin page has an "advanced search" functionality. You can use it as the starting block … Well, what you have to do is really simple, in fact: just remove the unnecessary fields from the search form and show the form always, and done.

As for the inline search filter of the grid, you can turn it off by setting "filter" property to null.

[color="#006400"]/* The 2nd topic merged to the 1st */[/color]