I have a button in a CGridView that preforms 2 an onclick events that opens a CJuiDialog, and preforms a JQuery ajax get call. The CJuiDialog opens as expected. The JQuery ajax get call sends two parameters to a function in the view’s controller. The controller generates a CSqlDataProvider. At this point everything works. Next a renderPartial is called that will populate the CJuiDialog. If I call the renderParial without the trailing “,false,true” everything works fine, but I cannot paginate in the CJuiDialog. If I add the trialing “,false,true” to the renderParial I get the following warning in my Chrome console:
The ajax pagination works in the CJuiDialog, but if I close the CJuiDialog and try and open the CJuiDialog again by clicking on any of the button’s in the CGridView I get the following error:
and the CJuiDialog will not open.
Here is my code:
admin.php View:
<script type="text/javascript">
...
function getNotes(Iid) {
var jsonObject = new Object();
jsonObject.id = Iid;
jsonObject.subject = "Inventory";
var jsonObject = {
"id" : Iid,
"subject" : "Inventory"
};
var jsonString = JSON.stringify(jsonObject);
$.ajax({
type: 'GET',
url: '/note/ajaxGetNoteList?id='+Iid+'&subject=Inventory',
async: true,
success: function (data) {
$("#noteD").html(data);
inventoryID = Iid;
}
});
}
...
</script>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'inventory-grid',
'dataProvider'=>$model->inventorySearch(),
'filter'=>$model,
'template' => '{summary}{pager}{items}{pager}{summary}',
'enableSorting'=>true,
'columns'=>array(
...
array(
'header'=>'',
'htmlOptions' => array('class' => 'button-column', 'style'=>'width:74px;'),
'type'=>'raw',
'value'=> function($data) {
if($data->getNoteID($data->InventoryID)){
$noteLink = '<a class="note" onclick="getNotes('.$data->InventoryID.'); $(\'#noteD\').dialog(\'open\'); return false;" title="Note" href="javascript:void(null)"><img src="/customAssets/gridview//note-icon.png" alt="Note"></a>';
}else{
$noteLink = '<a class="note" onclick="createNoteForm('.$data->InventoryID.', this); $(\'#noteD\').dialog(\'open\'); return false;" title="Note" href="javascript:void(null)"><img src="/customAssets/gridview//addnote-icon.png" alt="Note"></a>';
}
return '<a class="view" title="View" href="/inventory/view/'.$data->InventoryID.'"><img src="/customAssets/gridview//view.png" alt="View"></a>
<a class="update" title="Update" href="/inventory/update/'.$data->InventoryID.'"><img src="/customAssets/gridview//update.png" alt="Update"></a>
<a class="delete" title="Delete" href="/inventory/delete/'.$data->InventoryID.'"><img src="/customAssets/gridview//delete.png" alt="Delete"></a>
'.$noteLink;
},
//custom clear filter button in the thead
'filter' => CHtml::link('<img src="/customAssets/gridview//clearsearch.png" alt="Clear Search">', '/inventory/admin/1',array(
'id' => 'cbcwr',
'style' => 'text-align:center;display:block;',
'title' => 'Clear Search',
)),
),
)));
//Creates a jquery modal
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'noteD',
// additional javascript options for the dialog plugin
'options'=>array(
'title'=>'Note',
'width' => '700',
'height' => '675',
'autoOpen'=>false,
'buttons'=>array(
'Ok'=>'js: function() {
$(this).dialog(\'close\');
}',
),
),
));
//end of modal
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
NoteController.php Controller:
...
public function actionAjaxGetNoteList()
{
$inventoryId = $_GET['id'];
$subject = $_GET['subject'];
$count=Yii::app()->db->createCommand('SELECT COUNT(*) FROM [dbo].[Note] Where SubjectID = '.$inventoryId.' And NoteName = \''.$subject.'\'')->queryScalar();
$sql='SELECT * FROM [dbo].[Note] Where SubjectID = '.$inventoryId.' And NoteName = \''.$subject.'\' Order by CreatedBy Asc';
$dataProvider=new CSqlDataProvider($sql, array(
'keyField' => 'NoteID',
'totalItemCount'=>$count,
'sort'=>array(
'attributes'=>array(
'CreatedDateTime',
),
),
'pagination'=>array(
'pageSize'=>5,
),
));
/*
$this->renderPartial('application.views.note._list',array( // No Error But will not perform ajax pagination
//'model'=>$model,
'dataProvider' => $dataProvider,
'inventoryId' => $inventoryId,
'count' => $count,
));
*/
$this->renderPartial('application.views.note._list',array( // Synchronous XMLHttpRequest Error, will preform ajax pagination
//'model'=>$model,
'dataProvider' => $dataProvider,
'inventoryId' => $inventoryId,
'count' => $count,
),false,true);
}
Please let me know if any other info is needed. Any help will be greatly appreciated!