Yii CGridview过滤器日期选择器

tjvv9vkg  于 2022-11-09  发布在  其他
关注(0)|答案(3)|浏览(167)

我已经看了论坛关于制作自定义cgridview。。我想让过滤器使用日期时间选择器。
日期时间选取器:
我已经可以包含datetimepicker了,但是当我选择日期时,它出错了。:(..我在数据库上的日期数据类型是'timestamp'

这是密码

<?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>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</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',
        ),
    ),
)); 

?>

非常感谢你...

gwo2fgha

gwo2fgha1#

你可以改变模型类的search()函数,可以是这样的:

public function search() {
     ....
     $criteria->addCondition('DATE_FORMAT(time_field, \'%Y-%m-%d\') = ' . $this->time_field);
     ....
}

但是可能需要它来转换$this-〉time_field输入值。

vcirk6k6

vcirk6k62#

我有完全相同的问题,昨天和一些未知的原因,移动
'dateFormat' => 'yy-mm-dd'
从选项到htmloptions修复了我的问题。老实说,我在htmloptions和选项中都有它,到目前为止还没有任何问题

'htmlOptions' => array(
                    'id' => 'event_date_search',
                    'dateFormat' => 'yy-mm-dd'
                     ), 

 'options' => array(
                    'dateFormat' => 'yy-mm-dd'
                   ),

我希望这能有所帮助

k5hmc34c

k5hmc34c3#

你能把你的代码

'options' => array(
   'dateFormat' => 'yy-mm-dd'
)

'defaultOptions' => array(
   'showOn' => 'focus', 
   'dateFormat' => 'yy-mm-dd',
   'showOtherMonths' => true,
   'selectOtherMonths' => true,
   'changeMonth' => true,
   'changeYear' => true,
   'showButtonPanel' => true,
)

希望这对你有帮助
有关详细信息,请查看此链接http://www.yiiframework.com/wiki/318/using-cjuidatepicker-for-cgridview-filter/

相关问题