Php Yii通过IFRAME中不工作的按钮更新cgridview
我试图在更新mongodb后通过Cjuidiag框中的按钮更新CGridview。 我的代码: index.phpPhp Yii通过IFRAME中不工作的按钮更新cgridview,php,yii,cgridview,Php,Yii,Cgridview,我试图在更新mongodb后通过Cjuidiag框中的按钮更新CGridview。 我的代码: index.php <?php $this->beginWidget('zii.widgets.jui.CJuiDialog',array( 'id'=>'uploaddialog', 'options'=>array( 'title'=>'Edit Documents', 'autoOpen'=>false, 'modal'=>tru
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'uploaddialog',
'options'=>array(
'title'=>'Edit Documents',
'autoOpen'=>false,
'modal'=>true,
'width'=>958,
'height'=>623,
),
));
?>
<iframe id="cru-frame-struct" width="100%" height="100%" frameBorder="0" scrolling="yes" >
<?php //$this->renderPartial('uploaddocument',array()); ?>
</iframe>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');?>
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'Prd-grid',
'dataProvider'=>$dataProvider,
'columns' => array(
array(
'class'=>'CButtonColumn','template' => '{updateline}',
'buttons' => array(
'updateline' => array(
'options'=>array('style'=>'margin-left:20px'),
'imageUrl'=>\Yii::app()->request->baseUrl.'/images/update.png',
'url'=>'$this->grid->controller->createUrl("editdocument",
array("id"=>$data["Document_id"],"OriginObject"=>isset($data["OriginObject"])?$data["OriginObject"]:""))', //
'click'=>'function(){
$("#cru-frame-struct").attr("src",$(this).attr("href"));
$("#uploaddialog").dialog("open");
return false;
}',
)
),
),
array(
'name' => 'ID',
'type' => 'raw',
'value' => '$data["Document_id"]'
),
),
'htmlOptions' => array(
'class' => ""
),
));
?>
<?php echo CHtml::button('Update WorkFlow',array('id'=>'updworkflow','class'=>'btn','onclick'=>'workflow()','background-style'=>'none')); ?>
<h4><?php echo "Document Log";?></h4>
<?php
$mongo = new MongoClient( Yii::app()->mongodb->connectionString);
$dbname = Yii::app()->mongodb->dbName;
$temp = array();
$colname = 'Documents';
$collection = $mongo->$dbname->$colname;
$cursor = $collection->find(array("_id" => new MongoId($DocId)));
foreach ($dcursor as $ddoc) {
if(isset($ddoc['Workflows']))
{
$sdoc =($ddoc['Workflows']);
foreach ($sdoc as $wflw)
{
$temp ["Date"]= $wflw["Date"];
$temp ["Initials"]= $wflw["Initials"];
$temp ["Status"]= $wflw["Status"];
$temp ["Comments"]= $wflw["Comments"];
$pendarray[] = $temp;
}
}
}
$dataProvider = new \CArrayDataProvider ($pendarray,array('keyField'=>'Date'));
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'documentlog-grid',
'dataProvider'=>$dataProvider,
'columns' => array(
array(
'name' => 'Date',
'type' => 'raw',
'value' => 'isset($data["Date"])?$data["Date"]:""'
),
array(
'name' => 'Initials',
'type' => 'raw',
'value' => 'isset($data["Initials"])?$data["Initials"]:""'
),
array(
'name' => 'Status',
'type' => 'raw',
'value' => 'isset($data["Status"])?$data["Status"]:""'
),
array(
'name' => 'Comment',
'type' => 'raw',
'value' => 'isset($data["Comments"])?$data["Comments"]:""'
),
),
'htmlOptions' => array(
'class' => ""
),
));
?>
JavaScript
<script>
function workflow()
{
$.ajax({
type:"POST",
url :"<?php echo CController::createUrl('default/UpdateWorkflow'); ?>",
data:{"Comments":comments,
"Status":status,
"id":docid
},
success:function (data) {
$.fn.yiiGridView.update('documentlog-grid');
return true;
}
error: function(){
alert('failure ');
}
});
}
</script>
功能工作流()
{
$.ajax({
类型:“POST”,
url:“”,
数据:{“评论”:评论,
“地位”:地位,
“id”:docid
},
成功:功能(数据){
$.fn.yiiGridView.update('documentlog-grid');
返回true;
}
错误:函数(){
警报(“故障”);
}
});
}
我不确定这段代码中有什么错误。我正在用mongo数据填充网格。我想在mongodb中的每次更新/插入之后通过按钮刷新网格数据。
请帮我解决这个问题。你能这样试一下,告诉我它是如何工作的吗:
$('documentlog grid')。yiiGridView('update')代码>
也可以从浏览器控制台试试。我正在传递变量,更新工作正常,我的问题不是刷新网格。如果按下按钮并等待Ajax post完成后点击F5
,网格是否会更新?在Ajax调用中,您尝试设置complete:function(数据){$.fn.yiiGridView.update('documentlog-grid');}
以在任何情况下运行更新(即使未成功)。@Selvi,您说过“使用mongo数据填充网格”。您如何形成$dataProvider?您能公开代码吗?我在success var IFRAME=document.getElementById('cru-frame-resgrid');IFRAME.contentWindow.document.write(数据);IFRAME.contentWindow.document.close()中将此documentlog网格作为单独的IFRAME;
<script>
function workflow()
{
$.ajax({
type:"POST",
url :"<?php echo CController::createUrl('default/UpdateWorkflow'); ?>",
data:{"Comments":comments,
"Status":status,
"id":docid
},
success:function (data) {
$.fn.yiiGridView.update('documentlog-grid');
return true;
}
error: function(){
alert('failure ');
}
});
}
</script>