Yii Framework Forum: Filter CGridView with dateStart and dateEnd - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Filter CGridView with dateStart and dateEnd Rate Topic: ***** 1 Votes

#1 User is offline   zitter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 14-July 09

Posted 16 May 2010 - 05:01 AM

Hi, is it possible to filter column "dateStart" and column "dateEnd" in a CGridView using a sort of date picker in filter row?
I've created a CGridView using 1.1.2 yiic console (very nice, indeed) and it display something like 00-00-0000 00:00 in dateStart and dateEnd columns, in the row where filters are. Now I would like to improve that, using a date picker. Any suggestion?

TIA
Danilo
0

#2 User is offline   Mahdi 

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

Posted 19 October 2010 - 03:51 AM

Hello zitter,
Have you found a solution? I have the same problem :( .
Thank you.
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 October 2010 - 06:31 AM

You can use the property filter of CDataColumn.

You can set it in items:

items=>array(
   dateStart=>array(
      [...]
      'filter'=>$this->widget('CJuiDatepicker'),
  ),
),

0

#4 User is offline   Mahdi 

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

Posted 19 October 2010 - 07:01 AM

I used this :
<?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('CJuiDatepicker'),
		),           
        ),
)); ?>

But it does not work, Here is the error :
CJuiDatePicker must specify "model" and "attribute" or "name" property values.
0

#5 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,035
  • Joined: 30-October 09
  • Location:UK

Posted 19 October 2010 - 07:15 AM

View Postzaccaria, on 19 October 2010 - 06:31 AM, said:

You can use the property filter of CDataColumn.

You can set it in items:

items=>array(
   dateStart=>array(
      [...]
      'filter'=>$this->widget('CJuiDatepicker'),
  ),
),



'items' or 'columns'? I tried it like this:

'columns'=>array(
	array(
		'name'=>'register_date',
		'value'=>'$data->RegisterDate',
		'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array('model'=>$model, 'attribute'=>'register_date')),
	),
),


But then I get an error: Object of class CJuiDatePicker could not be converted to string

in the renderFilterCellContent() function of CDataColumn.php.
0

#6 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 October 2010 - 08:01 AM

GSTAR, you are right, is columns, not item.

try with:
'columns'=>array(
        array(
                'name'=>'register_date',
                'value'=>'$data->RegisterDate',
                'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array('model'=>$model, 'attribute'=>'register_date'), true),
        ),
),


The fourth parameter should capture the output and return the html.
0

#7 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,035
  • Joined: 30-October 09
  • Location:UK

Posted 19 October 2010 - 08:07 AM

Just tried it but nothing happens when clicking in the filter field. Have you tested this?
0

#8 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 October 2010 - 08:13 AM

No, I didn't.

I guess that you should write some javascript for make the validation happen at the selection of the date.
0

#9 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 October 2010 - 08:21 AM

I just tested right now and there is a problem with clientScript.

The calendar does the search the first time, but later it doesn't work anymore. The only solution here is to work without the widget, inlcude manually Jquery-ui javascript and CSS and call Jquery.datepicker manually.
0

#10 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 October 2010 - 08:50 AM

Ok, how I tested and I got a solution:
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'town-description-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'afterAjaxUpdate'=>"function(){jQuery('#".CHtml::activeId($model, 'town_id')."').datepicker([])}",
	'columns'=>array(
		array(
			'name'=>'town_id',
			'value'=>'$data->town->recordDescription',
            'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array('model'=>$model, 'attribute'=>'town_id'), true),

		),
		'title',
		'description',
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>


We have to specify the filter as CJuiDatepicker, and it is working only the first time.

In order to make it work after ajaxUpdate, we have to set the property afterAjaxUpdate.

Hope this helps
0

#11 User is offline   Mahdi 

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

Posted 19 October 2010 - 09:22 AM

Thank you for Help, but i have an error javascript :
d(a).zIndex is not a function
The file is : localhost/test/assets/b466101/jui/js/jquery-ui.min.js
0

#12 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 19 October 2010 - 09:29 AM

I have too sometime, but I dont't know what is, maybe a jquery error.

Try updating the framework, maybe they fixed it.
0

#13 User is offline   Mahdi 

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

Posted 19 October 2010 - 09:50 AM

ok, I'll do the update and inform you.
Thank you :)
0

#14 User is offline   GSTAR 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,035
  • Joined: 30-October 09
  • Location:UK

Posted 19 October 2010 - 09:58 AM

View Postzaccaria, on 19 October 2010 - 08:50 AM, said:

We have to specify the filter as CJuiDatepicker, and it is working only the first time.

It does not even work for me first time...
0

#15 User is offline   Mahdi 

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

Posted 19 October 2010 - 10:05 AM

View PostGSTAR, on 19 October 2010 - 09:58 AM, said:

It does not even work for me first time...

for me also
0

#16 User is offline   Mahdi 

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

Posted 19 October 2010 - 10:34 AM

I did the update, and it works, the calendar appears but when I click to select the date, an error appears:
$.param.querystring is not a function
File "jquery.yiigridview.js" line 146 :
options.url = $.param.querystring(options.url, options.data);
0

#17 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 20 October 2010 - 01:14 AM

I have really no words... on my installation with the lastest framework is working correctly... I tested with firefox, IE opera, chrome and safari on windows.

Such a huge number of different behavior, really no idea of what can be.
0

#18 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 20 October 2010 - 02:29 AM

$.param.querystring is defined in the "jquery.ba-bbq.js" file... check that you have included this JS file...
Find more about me.... btw. Do you know your WAN IP?
0

#19 User is offline   Mahdi 

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

Posted 20 October 2010 - 04:35 AM

The problem was solved :)
I did the update of the framework, but the file versions of jquery remain the same, so I used this statement to replace them with the latest versions ( Jquery 1.4.2 and Jquery UI 1.7.1 ) and it works well.
$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
    'jquery.js'=>Yii::app()->request->baseUrl.'/js/jquery-1.4.3.min.js',
    'jquery-ui-1.7.1.custom.min.js'=>Yii::app()->request->baseUrl.'/js/jquery-ui-1.8.5.custom.min.js',
);

Thank you for all.
0

#20 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 20 October 2010 - 04:54 AM

MAybe you should clean assets and runtime after the update, that can explain why your file didn't changed.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • 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