Yii Framework Forum: Yii - How Can I Filter The Rows In A Gridview By Using Radiobuttons In Search-Form - Yii Framework Forum

Jump to content

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

Yii - How Can I Filter The Rows In A Gridview By Using Radiobuttons In Search-Form

#1 User is offline   Rudra 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 118
  • Joined: 12-July 13

Posted 25 September 2013 - 01:50 AM

I'm new to Yii Framework.
I created radiobuttonlist out of two fields in search form-(`Approval,ReviewedDate`).
    <div class="row">
    		<?php #echo $form->label($model,'ReviewedDate'); ?>		
                    <?php echo $form->radioButtonList($model, 'ReviewedDate', 
            array('1' => 'Reviewed', '' => 'Not Reviewed')
        ); ?>
    	</div>
      
           <div class="row"> 
    	            <?php echo $form->radioButtonList($model, 'Approved', 
            array('0' => 'Rejected', '1' => 'Approved')
        ); ?> 
    	</div>  

Now I have another two fields in the search form (`Updateddate`,`createddate`).
Such that I use the search form to filter the values of gridview accordingly.

Suppose, I
1. click on the `reviewed` radiobutton, all records where (updateddate>createddate) and (revieweddate=0000-00-00 00:00:00) should be displayed.
2. click on the `not reviewed` radiobutton, all records where (updateddate=createddate) and (revieweddate=NULL) should be displayed.
3. click on the `approved` radiobutton, all records where (updateddate>createddate) and (revieweddate!=0000-00-00 00:00:00) and (approved=1) should be displayed.
4. click on the `rejected` radiobutton, all records where (updateddate>createddate) and (revieweddate!=0000-00-00 00:00:00) and (approved=0)should be displayed.
By default, revieweddate is NULL. When I update the form the value of revieweddate changes to **0000-00-00 00:00:00** and the value of updateddate changes to the currenttime.
Below is the model code:
    public function search()
    	{
    		// Warning: Please modify the following code to remove attributes that
    		// should not be searched.
    
    		$criteria=new CDbCriteria;
                    $criteria->with=array('apartment');
    		$criteria->compare('t.Id',$this->Id);
    		$criteria->compare('Approved',$this->Approved);
    		$criteria->compare('CreatedDate',$this->CreatedDate,true);
                $criteria->compare('UpdatedDate',$this->UpdatedDate,true); 
                $criteria->compare('ReviewedDate',$this->ReviewedDate,true);
                      if($this->ReviewedDate != '') 
                    {
                    $criteria->addCondition('ReviewedDate '.($this->ReviewedDate=="0000-00-00 00:00:00" ? 'IS NOT NULL' : 'IS NULL'));
                    
                    }
                    else 
                    { 
                    $criteria->addCondition('ReviewedDate IS NULL');                 
                    }
    
                    if (isset($this->Approved) && !empty($this->Approved)) {
                            $criteria = new CDbCriteria;
                            $criteria->select = 't.*';
                            $criteria->addCondition("approved='" . $this->Approved . "'");
                    }
    
                
    		return new CActiveDataProvider($this, array(
    			'criteria'=>$criteria,
    		));
    	}
    }
     

How can I filter the above conditions with the use of radiobuttons in search-form
0

#2 User is offline   Jai Rifluxyss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 18-September 13

Posted 07 November 2013 - 04:52 AM

Add addCondition statements before the first compare statement. Next to the ,

$criteria->with=array('apartment');
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