Problem updating gridview using a datepicker

Hi

I’ve got a problem with my CGridview. One of the fields in my grid view is a date and I want to be able to filter this field in the grid view. I want to do this by using a CJuiDatePicker.

I’ve got two text field and a button in a form above the grid view in each text field I want to select a date using the date picker and when I push the button I want the grid view to update and show the records between these two dates. Is this possible using Ajax or by using another method.I hope you can make sense of my explanation.

Code for the date pickers:


<?php


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

    'name'=>'firstDate',

    'options'=>array('showAnim'=>'fold',

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

    ),

    'htmlOptions'=>array(

        'style'=>'height:20px;',

    ),

));

?>

Grid view:


<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'aanwezig-grid',

	'dataProvider'=>$model->search(),

	

	'filter'=>$model,

	

	'columns'=>array(

			'firstname',

			'name',

			'group',

			'date',

			'time',

		

		array(

			'class'=>'CButtonColumn',

			

		),

	),

)); ?>

Thanks

Hi,

here is the solution :




<?php

$this->widget('zii.widgets.grid.CGridView', array(

        'id'=>'facture-grid',

        'dataProvider'=>$model->search(),

        'filter'=>$model,

        'columns'=>array(

                FullNumFact,

		array('name'=>'DateFact',

			'value'=>'$data->DateFact',	

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

							'model'=>$model,

							'attribute'=>'DateFact',

							'options'=>array(

								'showButtonPanel'=>true,

								'changeYear'=>true,

								)

							),

							true),

			'htmlOptions'=>array('width'=>'80','style'=>'text-align:center'),

		),                

               'NomClient',

             array('class'=>'CButtonColumn'),

        ),

        'afterAjaxUpdate'=>'function(){

					jQuery("#'.CHtml::activeId($model, 'DateFact').'").datepicker({showButtonPanel:true, changeYear:true});

				}',

));

?>



Hi

Thanks for the quick reply. Now I get the following error message "Object of class CJuiDatePicker could not be converted to string". Any idea why?

Thanks.

Hi,

I had the same problem, read this topic, it contains the same subject.


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

 array(

  'model'=>$model,

  'attribute'=>'fecha_reservacion', //fecha_reservacion is an attribute from my Model

 ),

 true);

That “true” should make it work! ;)

Thank you very much Mahdi, it was perfect for me :rolleyes:

I have the only problem that after the first search is performed, the date picker widget does not show anymore, and for further date searches the only thing I can do is to reload the page <_<

Any ideas why?

I have the same problem by using TbGridView and TbDatePicker.

Solved by using


'ajaxUpdate'=>false

property in CGridView (or TbGridView).

Hi,


'ajaxUpdate'=>false

will devoid us with all the magic of CGridView autoloading feature. It will force the page to load on every request.

I have solved it by adding this setting option in my CGridView


'afterAjaxUpdate'=>"js:function(){

jQuery('#Property_log_date').datepicker({'showButtonPanel':true,'changeYear':true});

}",

where "Property_log_date" is the id of the field which is attached to the datepicker. Property is the model name and log_date is the fieldname.

@DaveMentens In your case it would be like this




$this->widget('zii.widgets.grid.CGridView', 

array(        

'id'=>'facture-grid',        

'dataProvider'=>$model->search(),        

'filter'=>$model,

'afterAjaxUpdate'=>"js:function(){

jQuery('#Property_log_date').datepicker({'showButtonPanel':true,'changeYear':true});

}",        

'columns'=>array(

.....



Works for me :rolleyes: