Yii Framework Forum: Just Learned - Yii Framework Forum

Jump to content

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

Just Learned Just learned yii datepicker with filter option in cgridview Rate Topic: -----

#1 User is offline   Sivanthi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 14-February 13
  • Location:Nagercoil, Kanya Kumari, Tamilnadu. India

Posted 15 March 2013 - 04:31 AM

First should declare two variables in model

public $from_date,$to_date;


Then add following lines in the search function [model]

if(!empty($this->to_date) && !empty($this->from_date))
{
$criteria->condition = "dat  between '$this->from_date' and  '$this->to_date'";
}



The following lines need in the view file to display form


<div id="search">

$this->beginWidget('zii.widgets.CPortlet', array(

'title'=>"Search",

));

<?php 

$form=$this->beginWidget('CActiveForm', array( 'id'=>'page-form',                                                                   	                                                            	'enableAjaxValidation'=>true,)); 

?>
																			
	<b>From :</b>

	<?php

$this->widget('zii.widgets.jui.CJuiDatePicker', array(

       'name'=>'from_date',  // name of post parameter

					'value'=> '',//Yii::app()->request->cookies['from_date']->value,

		     'options'=>array(

					  	'showAnim'=>'fold',

						       'dateFormat'=>'yy-mm-dd',
					),'htmlOptions'=>array(
				       'style'=>'height:20px;'
				       ),
				       ));

     ?>

<br /><b>To :</b>

  	<?php

     $this->widget('zii.widgets.jui.CJuiDatePicker', array(

		'name'=>'to_date',

				     'value'=> '',//Yii::app()->request->cookies['to_date']->value,

					'options'=>array(

								     'showAnim'=>'fold',

								  	'dateFormat'=>'yy-mm-dd',
								  	),

				     'htmlOptions'=>array('style'=>'height:20px;),));

       ?>

  <?php echo CHtml::submitButton('Search',array('id'=>'searchbtn')); ?>

     [b]<?php $this->endWidget(); ?>[/b]

<?php $this->endWidget();?>
                         	

</div>



Finally add following lines in the controller/admin function

if(!empty($_POST))
{

$model->from_date = $_POST['from_date'];

$model->to_date = $_POST['to_date'];

}


Thats it!

Attached File(s)


0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,085
  • Joined: 16-February 11
  • Location:Japan

Posted 16 March 2013 - 02:06 AM

/* Moved from "General Discussion for Yii 1.1.x" to "Tips, Snippets and Tutorials" */

Would you please revise the post to make your code more readable?
0

#3 User is offline   Sivanthi 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 14-February 13
  • Location:Nagercoil, Kanya Kumari, Tamilnadu. India

Posted 19 March 2013 - 10:03 PM

View Postsoftark, on 16 March 2013 - 02:06 AM, said:

/* Moved from "General Discussion for Yii 1.1.x" to "Tips, Snippets and Tutorials" */

Would you please revise the post to make your code more readable?



sorry for the delay. now code has been reformatted for ease of reading.
1

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