How To Filter The Rows Of A Gridview In Yii Using Radio Buttons

I used the below code to create two radio buttons(approved messages and rejected messages) in Yii framework

<?php echo CHtml::activeRadioButtonList($model, 'Approved', array('Approved Messages', 'Rejected Messages'), array('labelOptions'=>array('style'=>'display:inline'),'separator'=>'')) ?>

Now I have to filter and display all the rows in CGridView of the table where column ‘approved’ has value=1 when I click on “approved messages” radio button and all the rows in CGridView of the table where column ‘Approved’ has value=0 when I click on “rejected messages” radio button. How can I do this

Can anyone help me on this

Hi,

you can write the query on model search function


public function search() {

		if (isset($this->Approved) && !empty($this->Approved)) {

			$criteria = new CDbCriteria;

			$criteria->select = 't.*';

                        $criteria->addCondition("approved='" . $this->Approved . "'");

		}

}

i hope it’s work fine

Thanks for the reply Ankit, but this isn’t working. Other than this should I have to change something in controller or any other file.

Hi,

can you post the admin grid code…

Can anyone help me

Anyone please help me on this

Hi Rudra,

As Ankit has suggested, we can filter the rows of CGridView by using the model’s search function.

I would place the radio buttons inside the advanced search form.