Yii Framework Forum: Cdbcriteria On Cgridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cdbcriteria On Cgridview Rate Topic: -----

#1 User is offline   adrianna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 19-March 14

Posted 13 May 2014 - 04:26 AM

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.
Attached File  Screenshot from 2014-05-13 17:19:24.png (22.71K)
Number of downloads: 5

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',		
	
	),
	));
	}

0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,668
  • Joined: 04-March 10
  • Location:UK

Posted 13 May 2014 - 04:33 AM

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.
0

#3 User is offline   adrianna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 19-March 14

Posted 13 May 2014 - 04:40 AM

View PostKeith, on 13 May 2014 - 04:33 AM, said:

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.
0

#4 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,668
  • Joined: 04-March 10
  • Location:UK

Posted 13 May 2014 - 04:56 AM

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.
0

#5 User is offline   adrianna 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 19-March 14

Posted 13 May 2014 - 05:03 AM

View PostKeith, on 13 May 2014 - 04:56 AM, said:

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users