Приветствую.
Тут такое дело. Я написал виджет DatePicker и использую его в фильтрах CGridWiew.
array(
'name' => 'created',
'value' => 'Yii::app()->format->formatDate($data->created)',
'type' => 'raw',
'htmlOptions' => array('class' => 'span1'),
'filter' => $this->widget('application.widgets.TDatePicker.TDatePicker', array(
'model' => $model,
'attribute' => 'created',
'htmlOptions' => array('id' => 'created'),
), true)
),
Виджет работает, с ним проблем нет. Проблема в том, что я хочу чтобы дата в фильтре была в формате d.m.Y. В клиентских скриптах я устанавливаю формат через options виджета.
Но после перезагрузки грида, дата в поле фильтра выводится в формате mysql (Y-m-d).
Перепробовал уже кучу вариантов, пробовал даже в value фильтра указывать
'value' => 'Yii::app()->format->formatDate($model->created)',
ни в какую.
Сейчас сделал формат даты в методе run виджета
public function run() {
parent::run();
list($name, $id) = $this->resolveNameID();
if ($this->hasModel()) {
$attribute = $this->attribute;
if (!empty($this->model->$attribute)) {
$this->model->$attribute = Yii::app()->format->formatDate($this->model->$attribute);
}
echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
} else {
echo CHtml::textField($name, $this->value, $this->htmlOptions);
}
$this->registerClientScript($id);
}
Но это костыль. Т.к. виджет может использоваться не только в фильтрах грида, но и формах. И если в фильтрах нужна только дата, то в формах нужно будет и время.
Поэтому как-то хотелось бы указывать виджету именно формат даты или метод, которым дату форматировать.
Подскажите, как бы вы сделали это по правильному?