0

I'm using two radiobuttons in advanced search form, they are reviewed and not reviewed. When I click on reviewed it should filter for multiple search box in Gridview and display the result. There are other three fields 'Updated date','reviewed date' and 'created date' also. Suppose, I click on the reviewed button. It should check for the condition updated time is greater than created date and reviewed date is default value(0000-00-00 00:00:00) and display the results in gridview.

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

Similarly, when I click not reviewed, it should check for updateddate=createddate and revieweddate=NULL.

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

Below is the code what I have tried, but I'm not getting proper results. How can I execute the correct results.

    $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');
}
user2770039
  • 59
  • 1
  • 2
  • 14

1 Answers1

0

you can use a customer filter in your grid view, like a drop down, and get that fields value and implement your logic there, like:

in your view:

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

and in your saerch function catch this custome fields value:

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

cheers

Developerium
  • 7,155
  • 5
  • 36
  • 56