Checkbox Filtering

I have obtained a grid view using a dataprovider and criteria.Now I want to use this grid view to filter some more data using checkboxes.How to do that?

NOTEI have not used the filter option of the gridview.


I have the following output in the form of grid:

1 VanPersie Soccer

2 Beckham Soccer

3 Schumacher F1

4 Federer Tennis

Now I want to have 3 checkboxes each for soccer,f1 and tennis.But When I select any of these three I should get the desired rows.For e.g

Selecting soccer I should get the first two rows…

Yes you can pass check box value to controller on checkbox checked and you can filter model from there which will use as dataprovider.


Also note that you posted this topic in forum "Miscellaneous" section, it had to posted in "General Discussion"


Will you have these checkboxes outside the grid or inside it (in a column)?

Provided that you use standard Gii CRUD, you’d use controller’s admin action and model’s search() method.

There are two steps:

  • using $_GET array or model virtual attributes

  • checking whatever you implement above in the controller’s admin action or in the model’s search(). If there are radio buttons (eg only one can be selected at once) you can just use the controller action and pass the selected value to the $model after unsetting its attributes (standard Gii’s CRUD). For actual checkboxes, you’d have to check the values and build a criteria using ‘OR’.

Yes I know it’s vague but if it doesn’t ring any bell, please provide more details about what you want to achieve.

Let me clear some facts:

Firstly I am not using controller’s admin action and model’s search method.Instead I am passing a dataprovider from the controller itself.Secondly,I want the checkboxes outside the grid so that further filtering can be done.

Will you be rather more elaborate as I am not using filter option of the grid view.The search is based on some conditions imposed on the data provider.

Yes YearningforYii,

I m just saying that, you can pass check value to controller whatever you set and can filter the data as you want and can that as dataprovider…

[color="#006400"]/* Moved from Miscellaneous to General Discussion */[/color]

I deleted the double post and moved this to the right place.

You’re welcome. ;)

If you’re searching and/or filtering, you’d better do that in the model imho, ie a search()-like method. Now if you do it in the controller, you could still check like I said before the $_GET array or the model’s virtual attribute (which you would have declared in the model class):

public function actionGrid() {

    $criteria = new CDbCriteria;

    /* Your other criteria outside the checkbox thing */

    if (isset($_GET['YourCheckboxArray'])) {

        $criteria2 = new CDbCriteria;

        foreach ($_GET['YourCheckboxArray'] as $filteringCriteria) {


            $criteria2->compare('yourField', $filteringCriteria, false, 'OR'); // 'Soccer', 'Tennis', …





    $dataProvider = new CActiveDataProvider('YourModel', array('criteria' => $criteria));

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

        'dataProvider' => $dataProvider,



Thankx… :rolleyes: