CJuiDatePicker in CGridview as form field

落花浮王杯 提交于 2019-12-11 18:06:31

问题


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". 

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

回答1:


I think this question over here can help you out:

Use a widget in a statically-called method

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



来源:https://stackoverflow.com/questions/26057927/cjuidatepicker-in-cgridview-as-form-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!