1

Is this possible to show cgridview data using condition. like only show those data where status=1.

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-details-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
    'id',
    'name1',
    'p_address1',
    'phoneno',
    'email1',
    'owner_name',
    'position', 
    'status'
    array(
        'class'=>'CButtonColumn',
        'template'=>'{delete}',

     ),
),

));

The table have status 0 and 1. I only want those listings which status is 1.

UPDATE: if i changed search method like this

$criteria->compare('status',1);

It's worked perfectly. But is it a good practice?

uiTeam324
  • 1,215
  • 15
  • 34

1 Answers1

1

You show data from model in CGridView. You can add conditions as criteria. For example in your model in search method add

$criteria->addCondition('status = 1');
Ali MasudianPour
  • 14,329
  • 3
  • 60
  • 62
Krzysztof Sztompka
  • 7,066
  • 4
  • 33
  • 48