We can use a CJuiDatePicker for a CGridView inline filter.
I hope the following sample code fragment will be enough for you.
$this->widget('zii.widgets.grid.CGridView', array( 'dataProvider' => $model->search(), 'filter' => $model, 'afterAjaxUpdate' => 'reinstallDatePicker', // (#1) 'columns' => array( ... array( 'name' => 'due_date', 'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array( 'model'=>$model, 'attribute'=>'due_date', 'language' => 'ja', 'i18nScriptFile' => 'jquery.ui.datepicker-ja.js', // (#2) 'htmlOptions' => array( 'id' => 'datepicker_for_due_date', 'size' => '10', ), 'defaultOptions' => array( // (#3) 'showOn' => 'focus', 'dateFormat' => 'yy/mm/dd', 'showOtherMonths' => true, 'selectOtherMonths' => true, 'changeMonth' => true, 'changeYear' => true, 'showButtonPanel' => true, ) ), true), // (#4) ), ... ), )); // (#5) Yii::app()->clientScript->registerScript('re-install-date-picker', " function reinstallDatePicker(id, data) { $('#datepicker_for_due_date').datepicker(); } ");
That's all. Have fun.
Total 3 comments
Do you try to use 'value' property of CJuiDatePicker in the filter? Don't use 'name' and 'value', use $model and 'attribute' instead.
date picker filter will not return the date which I selected. I set the date column value to this
'value'=>'date("m/d/Y",strtotime($data->date_requested))'
I think this is due to hour and second values is not set. any help?
thanks pal its very useful for me
Leave a comment
Please login to leave your comment.