CGridView ajax delete does not work

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

Are you using RBAC or some role manager?

Hi Lukas,

Please, post the ajax result in Firebug after clicking the delete link, maybe there might be useful info.

Best regards,

Ricardo

Hi Ricardo, thanks for your reply. You pushed me to focus on how to catch an error, which was following:




$.param.querystring is not a function



Then I found, that I had included jquery.js twice (once default from yii engine and once mine) in my html head:




<script type="text/javascript" src="/game/assets/c7860054/jquery.js"></script>

<script type="text/javascript" src="/game/assets/c7860054/jquery.ba-bbq.js"></script>

<script type="text/javascript" src="/game/javascript/jquery-1.6.1.js"></script>

<script type="text/javascript" src="/game/javascript/jqueryslidemenu.js"></script>



So the problem is solved and all ajax request (delete, paging etc.) work now.

So thank you once again.

Lukas

Hi Lukas,

I also had same issue, your post helps me to sort out. No need to include jquery.js in admin section. It works fine now.

Thank you for posting the answer !!