Yii Framework Forum: Problem updating gridview using a datepicker - Yii Framework Forum

Jump to content

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

Problem updating gridview using a datepicker Rate Topic: -----

#1 User is offline   DaveMentens 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 10-February 11

Posted 10 February 2011 - 08:21 AM

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
0

#2 User is offline   Mahdi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 127
  • Joined: 23-August 10
  • Location:Tunisia

Posted 10 February 2011 - 08:49 AM

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});
				}',
));
?>

0

#3 User is offline   DaveMentens 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 10-February 11

Posted 10 February 2011 - 09:36 AM

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.
0

#4 User is offline   Mahdi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 127
  • Joined: 23-August 10
  • Location:Tunisia

Posted 11 February 2011 - 02:04 AM

Hi,

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

#5 User is offline   ecairol 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 02-May 11

Posted 04 June 2011 - 11:40 PM

View PostDaveMentens, on 10 February 2011 - 09:36 AM, said:

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


$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! ;)
1

#6 User is offline   backloop 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 13-November 11

Posted 07 February 2012 - 12:05 PM

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?
0

#7 User is offline   Giuseppe Santoro 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 15-October 12

Posted 06 November 2012 - 01:00 PM

View Postbackloop, on 07 February 2012 - 12:05 PM, said:

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.
0

#8 User is offline   Giuseppe Santoro 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 15-October 12

Posted 07 November 2012 - 03:26 AM

Solved by using
'ajaxUpdate'=>false
property in CGridView (or TbGridView).
0

#9 User is offline   Sharkgr8 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 06-June 12

Posted 16 January 2013 - 09:24 PM

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:
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