如何根据单选按钮显示gridview

时间:2013-09-25 11:28:28

标签: gridview yii yii-components

我在高级搜索表单中使用了两个radiobutton,它们经过审核而未经过审核。当我点击查看时,它应该过滤Gridview中的多个搜索框并显示结果。还有其他三个字段“更新日期”,“审核日期”和“创建日期”。假设,我点击了评论按钮。它应该检查条件更新时间是否大于创建日期,并且审查日期是默认值(0000-00-00 00:00:00)并在gridview中显示结果。

SQL query-Select * from test where (updateddate>createddate)and(revieweddate=='0000-00-00 00:00:00');  

同样,当我点击未查看时,它应该检查updateddate = createddate和examinedate = NULL。

   SQL query-Select * from test where (updateddate=createddate)and(revieweddate IS NULL);   

下面是我尝试过的代码,但是我没有得到正确的结果。如何执行正确的结果。

    $criteria->compare('ReviewedDate',$this->ReviewedDate,true);
             if($this->ReviewedDate != '') {
    $criteria->addCondition(
        'ReviewedDate ' . ($this->ReviewedDate=='1' ? 'IS NOT NULL' : 'IS NULL'));

}
else {
    $criteria->addCondition('ReviewedDate IS NULL');
}

1 个答案:

答案 0 :(得分:0)

您可以在网格视图中使用客户过滤器,例如下拉列表,并获取该字段值并在那里实现您的逻辑,例如:

在您看来

$this->widget('zii.grid.GridView' , array(
'id' => 'urGrid',
'dataProvider' => $model->search,
'columns' => array(
        array(
           'name' => 'ReviewedDate',
           'filter' => CHtml::dropDownList('customeField' , $_GET['customeField'] , array(0=>'not reviewed' , 1=>'reviewed' , 2=>'some other thing'))
        ),
         .
         .
         .
    ),
));

并在您的saerch函数中捕获此custome字段值:

public function search() {
    $criteria = new CDbCriteria;

    //$criteria->compare('col1', $this->col1);
    $criteria->compare('col2', $this->col2);
    .
    .
    .
    if(isset($_GET['customeField'])){  // implement your logic in here
        if($_GET['customeField'] == 1){
              $criteria->addCondition('t.updateddate > t.createddate);  //add your logic
              $criteria->compare('revieweddate' ,'0000-00-00 00:00:00'); //check for exact thing
         }
         else{ anothe thing ..}
    }

欢呼声