Hello everyone! hope you doing well
I am having a problem. I have a datepicker to filter in admin view (CGridView)
in the _search.php, I am calling it this way
echo $this->renderPartial('application.views.partials.PSelecFecha', array('model'=>$model,'name'=>'fecha_nacimiento'));
And in the php file, there is the widget
$this->widget('zii.widgets.jui.CJuiDatePicker',
array('model'=>$model,
'attribute'=>$name,
'value'=>$model->$name,
'language' => 'es',
'htmlOptions' => array(
//'readonly'=>"readonly"
),
'options'=>array(
'autoSize'=>false,
'defaultDate'=>$model->$name,
'dateFormat'=>'dd-mm-yy',
'buttonImage'=>Yii::app()->baseUrl.'/images/create_new.gif',
'buttonImageOnly'=>true,
'buttonText'=>'Fecha',
'selectOtherMonths'=>false,
'showAnim'=>'slide',
'showButtonPanel'=>false,
//'showOn'=>'button',
'showOtherMonths'=>false,
'yearRange'=>'-1910',
'changeMonth' => 'true',
'changeYear' => 'true',
'minDate'=>date("d-m-Y",strtotime("1910-01-01")), //fecha minima
),
));
and then, in the admin.php, I have
'afterAjaxUpdate' => 'reinstallDatePicker', // (#1)
in the cgridview properties, then at the end, I have
Yii::app()->clientScript->registerScript('re-install-date-picker', "
function reinstallDatePicker(id, data) {
$('#datepicker_nacimiento').datepicker();
$.datepicker.setDefaults($.datepicker.regional['es']);
}
");
and for the filter of the grid, I have
array(
'name' => 'fecha_nacimiento',
'value'=> '$data->fecha_nacimiento',
'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'fecha_nacimiento',
'language' => 'es',
'i18nScriptFile' => 'jquery.ui.datepicker-es.js', // (#2)
'htmlOptions' => array(
'id' => 'datepicker_nacimiento',
//'readonly'=>"readonly"
),
'defaultOptions' => array( // (#3)
'language' => 'es',
//'showOn' => 'focus',
'dateFormat' => 'dd-mm-yy',
'yearRange'=>'1960',
'minDate'=>date("d-m-Y",strtotime("1960-01-01")), //fecha minima
//'minDate'=>'date("Y-m-d")', //fecha minima
'maxDate'=>'date("Y-m-d")', //fecha maxima
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
//'showButtonPanel' => true,
)
),
true), // (#4)
),
I think I am doing it wrong because I am having problems with the format and filtering, but when I remove the advanced search form and left just the CGridView filters, it works fine. When there are two date pickers, they both crash!
Is there any simpler way to do it? I mean inserting the datepicker in gridview and _search and dont loosing the format and properties.
Thanks in advanced