CjuidatePickerがCGridViewとUNIXのタイムスタンプでの値には機能しませんか?
質問
this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'enableSorting'=>false,
'filter'=>$model,
'afterAjaxUpdate'=>"function() {
jQuery('#Page_created').datepicker(jQuery.extend(jQuery.datepicker.regional['en'],{'showAnim':'fold','dateFormat':'dd.mm.yy','changeMonth':'true','showButtonPanel':'true','changeYear':'true'}));
}",
'columns' => array(
'title' => array(
'name'=>'title',
// 'header'=>'Title',
'type'=>'raw',
'value'=>'CHtml::link($data->title,Yii::app()->request->baseUrl."/page/".$data->id)',
'headerHtmlOptions' => array('style'=>'width:250px;'),
),
array(
'name'=>'created',
'type'=>'raw',
'value' => 'date("j.m.Y", $data->created)',
'filter'=>false,
'filter'=>$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'created',
'language'=>'en',
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'dd.mm.yy',
'changeMonth' => 'true',
'changeYear'=>'true',
'showButtonPanel' => 'true',
),
),true),
'htmlOptions' => array('style' => 'width:90px;'),
),
.
質問: 選択した日に並べ替える必要があります。それを行う方法?
解決
2つの可能性があります:
1:プロの/複雑な方法
UNIX形式の日付の追加フィールドを入力します。 DatePickerには、このオプションがあり、目的を表示するためのフィールドとデータ操作目的で1つを指定します。これを要求に応じて送信する必要があるので、CDGridViewに追加の(非表示)フィールドを含めるように指示する必要があります。これには、タイムスタンプA CSSクラスを含む追加のフィールドにCRIDViewのFilterSelector-Property(http://www.yiframework.com/doc/api/1.1/に設定することができます。 cgridView#filterselector-detail - rel="nofollow"> http://www.yiframework.com/doc/api/1.1/cgridview#filterselector-detail )そのように、それはajax要求と共に送られます。
2:簡単な方法
あなたのモデルの検索方法では、あなたが最初にif (strpos($this->created, '.'))
と一緒に送信され、それをDB値と比較する前にそれを解析するだけで解釈することを最初に確認してください...間違いなく簡単な方法!検索方法内の完全なコードは次のようになります。
public function search() {
//parse date if necessary
if (strpos(($this->created, '.')) {
$this->created = CDateTimeParser::parse($this->created, 'dd.MM.yy');
}
$criteria = new CDbCriteria();
//other compares...
$criteria->compare('created', $this->created);
//even more compares...
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
.
すべての解析フォーマットを見るためには、GitHubのCDatetimeParserのコードをチェックします。 https://github.com/yiisoft/yii/blob/master/framework/utils/cdatetimeparser.php