CGridview中的CJuiDatePicker为表单字段

时间:2014-09-26 10:55:45

标签: php yii datepicker cgridview yii-chtml

我在CGridView中显示表单元素并希望使用datepicker,但它会抱怨

CDataColumn and its behaviors do not have a method or closure named "widget". 

我使用Use a widget in a statically-called method中描述的方法修改了DATEIN但是我认为它的工作原理部分就像我进行排序或者日期选择器不起作用一样。它仅适用于初始加载。

<script>
$(document).ready(function() {
    /*
    $("input[name*='DATEIN'] ").each(function(){
        jQuery(this).datepicker({'dateFormat':'<?=Yii::app()->params["localdate"]; ?>'});
    });
    */

    $("input[name*='datedone'] ").each(function(){
        jQuery(this).datepicker({'dateFormat':'<?=Yii::app()->params["localdate"]; ?>'});
    });
});
</script>

<?php 

$job = new Jobs();
$buttonPlus = CHtml::ajaxLink('Add New Line', $this->createUrl('addNewLine',array("id"=>$model->id)), array(
        'type' => 'POST',
        'data' => array('id' => $model->id),
        'success' => 'function(html){  $.fn.yiiGridView.update("jobs-grid"); $.fn.yiiGridView.update("detailsseismic-grid"); $.fn.yiiGridView.update("details3d-grid");  }'
));

$this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'jobs-grid',
        'dataProvider'=>$job->searchbyproject($model->PROJID),      
        'afterAjaxUpdate'=>'function(id,options){
                            $("#jobs-grid").children("table").children("thead").children("tr").children("th").children("a").each(function(){        
                                $(this).click(function(){
                                    var x = getQueryParams(this.href);
                                    if($("#detailsgeoscan-grid").length)
                                        $.fn.yiiGridView.update("detailsgeoscan-grid",{data:"sort="+x.sort});
                                    else if($("#detailsseismic-grid").length)
                                        $.fn.yiiGridView.update("detailsseismic-grid",{data:"sort="+x.sort});
                                    else if($("#details3d-grid").length)
                                        $.fn.yiiGridView.update("details3d-grid",{data:"sort="+x.sort});
                                });

                            });

                            $("#jobs-grid").children("div").children("ul").children("li").children("a").each(function(){                
                                $(this).click(function(){       
                                    var x = getQueryParams(this.href);
                                    if($("#detailsgeoscan-grid").length)
                                        $.fn.yiiGridView.update("detailsgeoscan-grid",{data:"Detailsgeoscan_page="+x.Jobs_page});
                                    else if($("#detailsseismic-grid").length)
                                        $.fn.yiiGridView.update("detailsseismic-grid",{data:"Detailsseismic_page="+x.Jobs_page});
                                    else if($("#details3d-grid").length)
                                        $.fn.yiiGridView.update("details3d-grid",{data:"Details3d_page="+x.Jobs_page});
                                });

                            });
        /*
                            $("input[name*=\'DATEIN\'] ").each(function(){
                                jQuery(this).datepicker({"dateFormat":"'. Yii::app()->params["localdate"]. '"});
                            });
            */          
                            $("input[name*=\'datedone\'] ").each(function(){
                                jQuery(this).datepicker({"dateFormat":"'. Yii::app()->params["localdate"].'"});
                            });
                        }',
        'summaryText' => '',
        'columns'=>array(
                array(
                        'name'=>'JOBNO',
                        'value'=>'CHtml::activeHiddenField($data, "[$row]JOBNO")' ,
                        'type'=>'raw',
                        'headerHtmlOptions' => array('style' => 'display:none;'),
                        'htmlOptions' => array('style' => 'display:none'),
                        'footer' => $buttonPlus,
                        'footerHtmlOptions'=> array('colspan' => '7'),
                ),
                array(
                        'name'=>'NAME',
                        'value'=>'CHtml::activeTextField($data, "[$row]NAME", array("size"=>25))' ,
                        'type'=>'raw',
                        'footerHtmlOptions'=> array('style' => 'display:none'),
                ),
                array(
                        'name'=>'SEQ',
                        'value'=>'CHtml::activeTextField($data, "[$row]SEQ", array("size"=>15))' ,
                        'type'=>'raw',
                        'footerHtmlOptions'=> array('style' => 'display:none'),
                ),
                array(
                        'name'=>'DATEIN',
                        //'value'=>'CHtml::activeTextField($data, "[$row]DATEIN", array("size"=>10))' ,
                        'value' => function ($data, $row, $column) {
                            $controller = $column->grid->owner;
                            echo $controller->widget('zii.widgets.jui.CJuiDatePicker', array(
                                                                'model'=>$data,
                                                                'attribute'=>'DATEIN',
                                                                // additional javascript options for the date picker plugin
                                                                'htmlOptions'=>array(
                                                                        'class'=>'datefield',
                                                                        'id' => 'Jobs_'.$row.'_DATEIN',
                                                                ),
                                                                'options' => array(
                                                                        'dateFormat' => Yii::app()->params["localdate"],
                                                                )
                                                        ),true);
                        },
                        'type'=>'raw',
                        'footerHtmlOptions'=> array('style' => 'display:none'),
                ),
                array(
                        'header'=>"Process Complete <div id='checkboxgroup'> $processcompleteheader </div>",
                        'value'=>'$data->getcheckboxProcesses($row)',
                        'type'=>'raw',
                        'footerHtmlOptions'=> array('style' => 'display:none'),
                ),
                array(
                        'name'=>'DATEDONE',
                        'value'=>'CHtml::activeTextField((count($data->jobsprocesscomplete)>0) ? $data->jobsprocesscomplete(array("order"=>"datedone desc")) : new Jobsprocesscomplete , "[$row]datedone", array("size"=>10))' ,
                        'type'=>'raw',
                        'footerHtmlOptions'=> array('style' => 'display:none'),
                        'sortable' => false,
                ),
                array(                      
                        'name'=>'COMMENTS',
                        'value'=>'CHtml::activeTextField($data, "[$row]COMMENTS", array("style"=>"width:150px"))' ,
                        'type'=>'raw',
                        'footerHtmlOptions'=> array('style' => 'display:none'),
                ),
                array(
                        'header'=>'<a id="deletealljobs" title="Delete All Lines" onclick="deleteAllJob(\'1409099\')" href="#">X</a>',
                        'class'=>'CButtonColumn',
                        'template'=>'{delete}',
                        'footerHtmlOptions'=> array('style' => 'display:none'),
                ),

        ),
));
?>

我从另一个视图中渲染它

$processcompleteheader = null;
    foreach ($processstages as $k => $v) {
        $processcompleteheader .= CHtml::Checkbox($k."_all",'',array("value"=>$k,"title"=>$v));
    }
    $lineListContent = "<div id='form_line_list'>
        <div style='display: block;
    left: 565px;
    position: absolute;
    top: 7px;'> " .CHtml::hiddenField("PROJID",$model->PROJID) . CHtml::hiddenField("id",$model->id) . CHtml::activeFileField(new Fileupload,'jobs', array('onChange'=>'showLoadDialog();submit(this)'))."<a id=clearfile href=# onclick='clearfile()' />X</a></div>";
    $lineListContent .= $this->renderPartial("/jobs/_formJobsGridview",array("model"=>$model,"processcompleteheader"=>$processcompleteheader),true);
    $lineListContent .= "</div>";

1 个答案:

答案 0 :(得分:0)

我认为这里的问题可以帮到你:

Use a widget in a statically-called method

基本上这个小部件可以由控制器调用,但在你的代码中,你试图通过gridview调用它。