I have two models users and userstatus. I want to display information from the two models in acgridview and be able to filter on all the column.
so far, i have managed to only display the information. My filtering is not working.Can anyone help me? for now only filtering on the first column, i.e the UserName column
Relations:
Users Model - ‘userstatus’ => array(self::HAS_ONE, ‘Userstatus’, ‘iUserId’),
Userstatus Model - ‘users’=>array(self::BELONGS_TO,‘Users’,‘iUserId’),
Search Method in userstatus model:
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('iUserStatusId',$this->iUserStatusId);
$criteria->compare('vcModel',$this->vcModel,true);
$criteria->compare('iUserStatus',$this->iUserStatus,true);
$criteria->with=array('users');
$criteria->addSearchCondition('users.vcUserName',$this->iUserId);
$criteria->compare('vcAppVersion',$this->vcAppVersion,true);
$criteria->compare('vcDataUsage',$this->vcDataUsage,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array('pageSize'=>200,),
//'order'=>field(iUserStatus,'Active','Inactive');
));
}
[b]
VIEW:[/b]
$this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'users-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array('header'=>'User','value' => '$data->vcUserName', 'filter' => CHtml::activeTextField($model, 'vcUserName'), ),
array('header'=>'Model','value'=>'$data->userstatus["vcModel"]'),
array('header'=>'Data Usage','value'=>'$data->userstatus["vcDataUsage"]', 'name'=>'userstatus.vcDataUsage', 'filter' => CHtml::activeTextField($model, 'vcDataUsage'), ),
array('header'=>'AppVersion','value'=>'$data->userstatus["vcAppVersion"]'),
array('header'=>'Status','value'=>function($data){
if($data->vcLoginStatus === "true"){
return "Active";
} else {
return "InActive";
}
}),
array(
'class'=>'CButtonColumn',
'template'=>'{view}',
),
),
));