Changes
Title
unchanged
Using CJuiDatePicker for CGridView filter
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
CJuiDatePicker, CGridView, filter
Content
changed
[...]
'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',[...]
Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
$('#datepicker_for_due_date').datepicker( //use the same parameters that you had set in your widget else the datepicker will be refreshed by default
$('#datepicker_for_due_date').datepicker(jQuery.extend({showMonthAfterYear:false},jQuery.datepicker.regional['ja'],{'dateFormat':'yy/mm/dd'}));
}
");[...]
- Call CController::widget() with the third parameter set to 'true'. (#4)
- Define 'afterAjaxUpdate' to call a javascript function that will reinstall the datepicker, because it will return to a plain textField each time the grid is updated by an ajax call. (#1) and (#5)
- I had to define language specific 'i18nScriptFile' option
manually when I first wrote this article. Setting 'language' option was not enough.
But now, you don't need to do it. (#2)
- Use 'defaultOptions' instead of 'options', otherwise you have to set those options again in the javascript function to reinstall the datepicker. (#3)
That's all. Have fun.
### More to read[...]