Cdbcriteria On Cgridview

How can I use CDbCriteria to allow only certain value of an attribute of a model on CGridView.

To explain it further, this is the preview.

5560

Screenshot from 2014-05-13 17:19:24.png

Now, how can I show only decided_mode = ‘Public Bidding’ without ‘Shopping’ using CDbCriteria?

This is the code I am working:




if (Yii::app()->user->checkAccess('user')){


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

	'id'=>'purchase-request-grid',

	'dataProvider'=>$model->searchCat($cat),

	'filter'=>$model,

	'selectionChanged'=>'checkCandidate', 

	'columns'=>array(

		//'id',

		'docutrack_no',

		array(

			'header'=>'Unit/Dept',

			'value'=>'$data->unit ." / ". $data->department',

		),

		'budget_code',

		'class_name',

		array(

			'name'=>'abc',

			'value'=>function($data) {

				return number_format($data->abc, 2);

			}

		),

		//'purpose',

		'proposed_mode',

		'decided_mode',

		'is_selected',		

	

	),

	));

	}



I’m not sure if I fully understand, but if you want to only show decided_mode when it differs from proposed_mode, you could do something like this:




    'columns'=>array(

        ...

        array(

            'name'=>'decided_mode',

            'value'=>function($data){

                if ($data->decided_mode === $data->proposed_mode)

                    return '';


                return $data->decided_mode;

            },

        ),

        ...

    ),



You should be able to figure out how to handle your specific requirements from the example above.

Thank you Keith :) Maybe i didn’t explained it clearly. Okay, what I want is to list only rows with Decided Mode = Public Bidding. I think CDbCriteria would be helpful but I just don’t know how to use it on CGridView.

You need to add a condition in your searchCat() method. Something like the following should work:




    $criteria->addColumnCondition(array('t.decided_mode'=>'Public Bidding'));



That assumes that you always want to show only those rows. Alternatively, you could control it with a column filter.

Thank You again Keith! :) It works for me now.