我已经阅读了关于制作自定义 cgridview 的论坛。我想让过滤器使用 datetimepicker。
日期时间选择器:
我已经可以包含 datetimepicker,但是当我选择日期时,它变成了错误。:(.. 我在数据库上的日期数据类型是“时间戳”
这是代码
<?php
$this->breadcrumbs=array(
'Events'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Event','url'=>array('index')),
array('label'=>'Create Event','url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('event-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Events</h1>
<p>
You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button btn')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'event-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'afterAjaxUpdate'=>"function(){jQuery('#event_date_search').datepicker({'dateFormat': 'yy-mm-dd'})}",
'columns'=>array(
array(
'type' => 'raw',
'name'=> 'event_image',
'value' => 'CHtml::image("'.Yii::app()->request->baseUrl.'/uploads/event/$data->event_image", "event_image" ,array("width"=>100))',
'filter'=> false,
),
'event_name',
array(
'name' => 'event_date',
'type' => 'raw',
'filter'=>$this->widget('zii.widgets.jui.CJuiDatepicker', array(
'model'=>$model,
'attribute'=>'event_date',
'htmlOptions' => array(
'id' => 'event_date_search'
),
'options' => array(
'dateFormat' => 'yy-mm-dd'
)
), true)
),
array(
'name'=>'published',
'filter'=>CHtml::dropDownList('Event[published]', '',
array(
''=>'',
'1'=>'Published',
'0'=>'Not Published',
)
),
'value' =>'($data->published==1)?"Published":"Not Published"',
),
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
));
?>
非常感谢...