本文介绍了CGridview中的CJuiDatePicker作为表单字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am displaying form elements in my CGridView and would like datepicker, but it complains

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

我已使用所述方法修改了 DATEIN 在使用小部件的静态调用方法中,认为它部分地工作,因为当我做一个排序或日期选择器不工作。

I have modified DATEIN using the method described in Use a widget in a statically-called method However i think it works partially as when i do a sort or the datepicker does not work. its working only on initial load.

<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'),
                ),

        ),
));
?>

我从另一个视图进行渲染

I render it on from another view

$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>";


推荐答案

我认为这里的问题可以为您提供帮助:

I think this question over here can help you out:

基本上,该小部件可以由控制器调用,但是在您的代码中,您尝试通过gridview调用它

Basically this widget can be called by the controller, but in your code you are trying to call it by the gridview.

这篇关于CGridview中的CJuiDatePicker作为表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 11:15