使用CGridView的CJUIDatePicker不起作用

时间:2012-06-05 12:39:28

标签: php yii

我试图在CGridView中包含一个Datepicker,如下所示,在网格视图中使用了datepicker小部件。

this->widget('zii.widgets.grid.CGridView', array(
'id'=>'order-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
    'order_id',
    'customer.address.firstname',
    'customer.address.lastname',
    /*array('name' => 'ordering_date',
        'value' => 'date("M j, Y", $data->ordering_date)'),
    */  

    array('name'=>'ordering_date',
                    'value'=>'$data->ordering_date',     
                    'filter'=>$this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                                    'model'=>$model,
                                                    'attribute'=>'ordering_date',
                                                    'options'=>array(
                                                            'showButtonPanel'=>true,
                                                            'changeYear'=>true,
                                                            )
                                                    ),
                                                    true),
                    'htmlOptions'=>array('width'=>'80','style'=>'text-align:center'),
            ),             
    array(
        'class'=>'CButtonColumn', 
        'template' => '{view} {rollback} {receive}{pack} {dispatch}{delivered}',
        'htmlOptions'=>array('width'=>'250px'),

        'buttons'=>array(
            'receive'=>array(
                'id'=>'receive',
                'name'=>'receive',
                'url'=>'$this->grid->controller->createUrl("/shop/order/admin&received=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
                'type'=>'submit',
                'imageUrl'=>'/mdg/images/Receive1.png',
                'visible'=>'($data->status=="pending")?true:false;'
             ),
             'pack'=>array(
                'id'=>'pack',
                'name'=>'pack',
                'type'=>'submit',
                'url'=>'$this->grid->controller->createUrl("/shop/order/admin&packed=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
                'click'=>'',
                'imageUrl'=>'/mdg/images/pack1.png',
                'visible'=>'($data->status=="received")?true:false;'
             ),
             'dispatch'=>array(
                'id'=>'dispatch',
                'name'=>'dispatch',
                'url'=>'$this->grid->controller->createUrl("/shop/order/admin&dispatched=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
                'click'=>'',
                'imageUrl'=>'/mdg/images/dispatch.png',
                'visible'=>'($data->status=="packed")?true:false;'
             ),
             'delivered'=>array(
                'id'=>'delivered',
                'name'=>'delivered',
                'url'=>'',
                'click'=>'',
                'imageUrl'=>'/mdg/images/delivered1.png',
                'visible'=>'($data->status=="dispatched")?true:false;'
             ),
             'rollback'=>array(
                'id'=>'rollback',
                'name'=>'rollback',
                'url'=>'$this->grid->controller->createUrl("/shop/order/admin&rollback=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
                'click'=>'',
                'imageUrl'=>'/mdg/images/rollback.jpg',
                'visible'=>'($data->status=="pending")?false:true;'
             ),
        ),
    ),


'status',

),
'afterAjaxUpdate'=>'function(){
                                    jQuery("#'.CHtml::activeId($model, 'ordering_date').'").datepicker({showButtonPanel:true, changeYear:true});
                            }',

)); ?>

本准则取自yiiframework论坛中的建议。但它什么都没做。

知道为什么会这样吗? 谢谢!

1 个答案:

答案 0 :(得分:2)

在这种情况下,我会将日期选择器放在_search视图中。如果您使用Gii生成CRUD,它应该已经存在,可以从admin视图中找到:

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?> <div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array( 'model'=>$model, )); ?> </div><!-- search-form -->