Yii Framework Forum: Zii.widgets.grid.cgridview Date Not Null - Yii Framework Forum

Jump to content

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

Zii.widgets.grid.cgridview Date Not Null Rate Topic: -----

#1 User is offline   coolPhp 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 15-December 10

Posted 05 March 2013 - 10:08 AM

Hi All

Is there a way I can tell the model to only get dates that are not null.

                $dataProvider->date_due = "IS NOT NULL";
                $dataProvider->date_completed = "IS NULL";



I am currently doing it this way but the filter does not work, however it works when the grid is frist loaded.

Controler
$dataProvider = new CompDiary('search');
$dataProvider->unsetAttributes();
                
$condition = 'date_due IS NOT NULL AND date_completed IS NULL';
                
if(isset($_GET['CompDiary'])) $dataProvider->attributes=$_GET['CompDiary'];
$dataProvider->condition = $condition;


model
if(!empty($this->condition)) $criteria->condition = $this->condition;
$criteria->compare('t.id',$this->id,true);
$criteria->compare('t.unix_time',$this->unix_time,true);
$criteria->compare('t.date_due',$this->date_due,true);
$criteria->compare('t.date_completed',$this->date_completed,true);

return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'pagination'=>array(
				'pageSize'=>Yii::app()->params['pageSize'],
				'pageVar'=>'page',
			),
			'sort'=>array(
				'defaultOrder'=>'checkType.area,date_due ASC',
				'sortVar'=>'sort',
			),
		));


Please any help
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 06 March 2013 - 01:05 AM

Dear Friend

Still I am not able to comprehend what is your exact requirement.

Anyway please check the following.

CONTROLLER.
public function actionAdmin()
	{
		$model=new CompDiary('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['CompDiary']))
			$model->attributes=$_GET['CompDiary'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}


MODEL
public function search()
{
		
	$criteria=new CDbCriteria;
        $criteria->compare('t.id',$this->id,true);
        $criteria->compare('t.unix_time',$this->unix_time,true);
        $criteria->compare('t.date_due',$this->date_due,true);
        $criteria->compare('t.date_completed',$this->date_completed,true);

//NOW ADD THESE TWO LINES

        $criteria->addCondition('t.date_due IS NOT NULL');
        $criteria->addCondition('t.date_completed  IS  NULL');

        return new CActiveDataProvider($this, array(
                        'criteria'=>$criteria,
                        'pagination'=>array(
                                'pageSize'=>Yii::app()->params['pageSize'],
                                'pageVar'=>'page',
                        ),
                        'sort'=>array(
                                'defaultOrder'=>'checkType.area,date_due ASC',
                                'sortVar'=>'sort',
                        ),
                ));

		
}


In admin.php use $model->search() as dataProvider.

Regards.
0

#3 User is offline   coolPhp 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 15-December 10

Posted 06 March 2013 - 03:20 AM

This fixed it thanks ::)


View Postseenivasan, on 06 March 2013 - 01:05 AM, said:

Dear Friend

Still I am not able to comprehend what is your exact requirement.

Anyway please check the following.

CONTROLLER.
public function actionAdmin()
	{
		$model=new CompDiary('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['CompDiary']))
			$model->attributes=$_GET['CompDiary'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}


MODEL
public function search()
{
		
	$criteria=new CDbCriteria;
        $criteria->compare('t.id',$this->id,true);
        $criteria->compare('t.unix_time',$this->unix_time,true);
        $criteria->compare('t.date_due',$this->date_due,true);
        $criteria->compare('t.date_completed',$this->date_completed,true);

//NOW ADD THESE TWO LINES

        $criteria->addCondition('t.date_due IS NOT NULL');
        $criteria->addCondition('t.date_completed  IS  NULL');

        return new CActiveDataProvider($this, array(
                        'criteria'=>$criteria,
                        'pagination'=>array(
                                'pageSize'=>Yii::app()->params['pageSize'],
                                'pageVar'=>'page',
                        ),
                        'sort'=>array(
                                'defaultOrder'=>'checkType.area,date_due ASC',
                                'sortVar'=>'sort',
                        ),
                ));

		
}


In admin.php use $model->search() as dataProvider.

Regards.

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