Yii Framework Forum: Gridview Filters - Yii Framework Forum

Jump to content

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

Gridview Filters Rate Topic: -----

#1 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 10-January 14
  • Location:India

Posted 14 July 2014 - 12:26 AM

Hello Friends.


In my app I have one alert page. That page will intimate that who are all having birthday for next 30 days. So i need to show only those rows display in my Cgridview. how can I do this???
0

#2 User is offline   mbala 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 156
  • Joined: 21-July 12
  • Location:Chennai, Tamilnadu, India

Posted 14 July 2014 - 12:47 AM

Try this code
<?php
public function search_next_30_days()
{

	$criteria=new CDbCriteria;
        $next_30_days= date('Y-m-d', strtotime("+30 days"));
        $today= date('Y-m-d');
	..............
	//$criteria->compare('emp_birthday',$this->emp_birthday,true);                
        $criteria->addBetweenCondition("t.emp_birthday",$today,$next_30_days,"AND");
        ..............
	return new CActiveDataProvider($this, array(
		'criteria'=>$criteria,
	));
}
?>    

0

#3 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 10-January 14
  • Location:India

Posted 14 July 2014 - 12:49 AM

View Postmbala, on 14 July 2014 - 12:47 AM, said:

Try this code
<?php
public function search_next_30_days()
{

	$criteria=new CDbCriteria;
        $next_30_days= date('Y-m-d', strtotime("+30 days"));
        $today= date('Y-m-d');
	..............
	//$criteria->compare('emp_birthday',$this->emp_birthday,true);                
        $criteria->addBetweenCondition("t.emp_birthday",$today,$next_30_days,"AND");
        ..............
	return new CActiveDataProvider($this, array(
		'criteria'=>$criteria,
	));
}
?>    


Is this in my controller rite.
Thank you bala.. and how can i use this in the filters in gridview
0

#4 User is offline   mbala 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 156
  • Joined: 21-July 12
  • Location:Chennai, Tamilnadu, India

Posted 14 July 2014 - 12:57 AM

View Postvijay p s, on 14 July 2014 - 12:49 AM, said:

Is this in my controller rite.
Thank you bala.. and how can i use this in the filters in gridview

No you have to add this code in your model and call this function in gridview.
Just use 'search_next_30_days' function instead of 'search'.
See the gridview code
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'emptermination-grid',
	'dataProvider'=>$model->search_next_30_days(),
	'filter'=>$model,
	'columns'=>array(
		'id',
		'employee_id',
		'emp_name',
		'emp_birthday',
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>

0

#5 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 10-January 14
  • Location:India

Posted 14 July 2014 - 01:12 AM

In my model
public function search_next_30_days()
{

        $criteria=new CDbCriteria;
        $next_30_days= date('Y-m-d', strtotime("-30 days"));
        $today= date('Y-m-d');
        //$criteria->compare('emp_birthday',$this->emp_birthday,true);                
        $criteria->addBetweenCondition("maturitydate",$today,$next_30_days,"AND");
        return new CActiveDataProvider($this, array(
                'criteria'=>$criteria,
        ));
}



In my Gridview:
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'alert-fd-grid',
	'dataProvider'=>$model->search_next_30_days(),
	'filter'=>$model,
	'columns'=>array(
		'add_id',
		'code',
		'catg_id',
		'head_id',
		'shead_id',
		'fdnumber',
		'fdname',
		'startdate',
		'noofyears',
		'maturitydate',
		'amount',
		'bank',
		'branch',
		'rateofinterest',
		'interestamount',
		'interest_bank',
		'interest_branch',
		'annual',
		array(
			'class'=>'CButtonColumn',
		),
	),
));

It shows no result found.. How can get sure its working or not
0

#6 User is offline   mbala 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 156
  • Joined: 21-July 12
  • Location:Chennai, Tamilnadu, India

Posted 14 July 2014 - 01:37 AM

View Postvijay p s, on 14 July 2014 - 01:12 AM, said:

It shows no result found.. How can get sure its working or not

Enable the log in 'config/main.php' file and find the sql query to run in database.
0

#7 User is offline   vijay p s 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 69
  • Joined: 10-January 14
  • Location:India

Posted 14 July 2014 - 04:59 AM

View Postmbala, on 14 July 2014 - 01:37 AM, said:

Enable the log in 'config/main.php' file and find the sql query to run in database.


Now its work bala..Thank you.
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