Hello,
I am new to Yii and I am struggeling with the following problem:
Delete button in CGridView does not make ajax call, so the delete does not work.
my admin.php view looks like this:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'event-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
//'id',
'type',
'resulttype',
//'resultValue',
'resultpositivity',
'description',
'descriptionfull',
/*
'descriptionatt',
'isnurable',
'repeatable',
*/
array(
'class'=>'CButtonColumn',
),
),
)); ?>
It generates following html for gridview delete:
jQuery('#event-grid a.delete').live('click',function() {
if(!confirm('Are you sure you want to delete this item?')) return false;
var th=this;
var afterDelete=function(){};
$.fn.yiiGridView.update('event-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(data) {
$.fn.yiiGridView.update('event-grid');
afterDelete(th,true,data);
},
error:function(XHR) {
return afterDelete(th,false,XHR);
}
});
return false;
});
jQuery('#event-grid').yiiGridView({'ajaxUpdate':['event-grid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'items','selectableRows':1,'pageVar':'Event_page'});
});
After clicking on delete button, the code above executes, but it always get stuck on the following line in jquery.yiigridview.js:
options.url = $.param.querystring(options.url, options.data);
and the only GET request processes and Error 400 rises.
actionDelete method in controller is default:
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
$this->loadModel()->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
//if(!isset($_GET['ajax']))
// $this->redirect(array('index'));
}
else
throw new CHttpException(400,
Yii::t('app', 'Invalid request. Please do not repeat this request again.'));
}
Could you please help me?
Thanks in advance.
Lukas