I have a gridview where I can search for items and delete them if desired. I am running into an issue where after an ajax call doing the search with a screen update, a second ajax call doing the delete and then updating the same screen causes only the data to be output minus the controls (gridview, etc). I know this is probably some collision with multiple jquery loading, but I am new at this and not sure how this is really supposed to be properly handled. Thanks
// first ajax search url call
echo CHtml::htmlButton('<i style="text-align: left; width: 2em" class="glyphicon glyphicon-search"></i> Search', array(
'onclick'=>'js: $.ajax({
type: "POST",
data: {campus: $("#id_errorCampus").val(), building: $("#id_errorBuilding").val(), room: $("#id_errorRoom").val(),
startDate: $("#id_errorStartTime").val(), endDate: $("#id_errorEndTime").val(),
filter: $("#id_errorFilter").val()},
datatype: "json",
url: "' .$url. '",
success: function(result){
var response = $.parseJSON(result);
$("#error-view").html(response.errorViewData);
}
})',
'id'=>'id_errorSearch',
'class'=>'btn btn-success',
));
public function actionSearchError()
{
$campus = $_POST['campus'];
$building = $_POST['building'];
$room = $_POST['room'];
$startDate = $_POST['startDate'];
$endDate = $_POST['endDate'];
$filter = $_POST['filter'];
$model = new MaintenanceForm();
$gridData['errorColumns'] = $model->buildColumnFormat();
$gridData['campuses'] = Helper::getCampuses("");
$gridData['errorData'] = $model->getErrorData($campus,$building,$room,$startDate,$endDate,$filter);
$gridData['id'] = 'View';
$gridData['mode'] = 'grid';
$result['errorViewData'] = $this->renderPartial('/maintenance/errorview', array('gridData'=>$gridData), true);
echo CJSON::encode($result);
yii::app()->end();
}
// 2nd call from grid button
$columnFormat['Delete'] = array('class'=>'CButtonColumn',
'template'=>'{newdelete}',
'header'=>'Delete',
'headerHtmlOptions'=>array('class'=>'gridclass', 'style'=>'color:white'),
'htmlOptions'=>array('style'=>'text-align:center'),
'buttons'=>array(
'newdelete'=>array(
'visible'=>'$data["role"] == "Administrator"',
'imageUrl'=>'images/delete.png',
'url'=>'yii::app()->createUrl("maintenance/deleteerror", array("data"=>$data["recordID"]))',
'options' => array(
'ajax' => array('type' => 'post',
'url'=>'js:$(this).attr("href")',
'success' => 'js:function(result){
response = $.parseJSON(result);
$("#error-view").html(response.errorViewData);
}'
)
),
),
),
);
public function actionDeleteError()
{
$id = $_GET['data'];
$model = new MaintenanceForm();
$model->deleteErrorData($id);
$gridData['mode'] = 'grid';
$gridData['errorColumns'] = $model->buildColumnFormat();
$errorParms = yii::app()->session->get('error-params');
$gridData['errorData'] = $model->getErrorData($errorParms['campus'],$errorParms['building'],$errorParms['room'],$errorParms['startDate'],$errorParms['endDate'],$errorParms['filter']);
$result['errorViewData'] = $this->renderPartial('/maintenance/errorview', array('gridData'=>$gridData), true);
echo CJSON::encode($result);
yii::app()->end();
}