multiple ajax calls on datagrid update

Hi,

I have a page that has between one and three datagrids.

They work correctly but…

When I use the ‘next’ and ‘prev’ page buttons on one of the grids (id = ‘products_grid’) I can see that more than one ajax call is made. In fact:

If there is only one datagrid on the page, one ajax call is made.

If there are two datagrids on the page, two ajax calls are made, and

If there are three datagrids on the page, three ajax calls are made.

Each datagrid has it’s own unique id.

I can see the ajax params for the three ajax calls has the id ‘products_grid’ of the datagrid I am pageing.

Any ideas?

Thanks a lot.

Chris.

try to set different ids for each grid

That is the first thing I checked. Each grid has it’s own id. :(

Well, then it doesnt make sense as this is the function that takes care of the update:




if(settings.ajaxUpdate.length > 0) {

				$(settings.updateSelector).die('click').live('click',function(){

					$.fn.yiiGridView.update(id, {url: $(this).attr('href')});

					return false;

				});

			}



settings.updateSelector for the pager is set as $(’#idofthegrid .pagerClass a’), could you check the AJAX calls (1+2+3) on Firebug? Maybe we get a hint there

Here are two screenshots.

There are three grids present.

Paging one grid causes 3 ajax calls.

Paging another causes 2 ajax calls.

The third grid doesn’t have enough data to page. I can change that if you like.

1394

firebird-datagrid1.png

1395

firebird-datagrid2.png

Thanks for helping.

Could you please post the code that generate the grids?

view




$this->renderPartial('/serviceoffer/offergrid',array('dataProvider'=>$offersMadeDataProvider,

							'isClient'=>$isClient,

							'unlocked' => $unlocked,

							'gridID'=>'offers-grid'),false,true);


$this->renderPartial('/serviceoffer/offergrid',array('dataProvider'=>$starredOffersDataProvider,

							'isClient'=>$isClient,

							'unlocked' => $unlocked,

							'gridID'=>'starred-offers-grid'),false,true);


$this->renderPartial('/serviceoffer/updated-offergrid',array('dataProvider'=>$updatedOffers,

						'gridID'=>'updated-offers-grid'),false,true);



The ‘updated-offers-grid’ uses an extended datagrid made by me but when I remove ‘updated-offergrid’ from the view I still get the same problem.

So, with ‘updated-offers-grid’ removed I only have 2 datagrid in the view and now ‘offers-grid’ makes 2 ajax call instead of 3, and ‘starred-offers-grid’ makes only 1 call instead of 2. :huh:

controller


$model=$this->loadModel();


// http://www.yiiframework.com/forum/index.php?/topic/13191-gridview-ajax-requests-entire-page/

if(Yii::app()->request->isAjaxRequest){

	if(isset($_GET['ajax'])){

		if($_GET['ajax'] == 'updated-offers-grid'){

			if($model->client == Yii::app()->user->getId()){

				$updatedOffers=Serviceorder::model()->getOfferUpdates($model->id);

				$this->renderPartial('/serviceoffer/updated-offergrid',array(	'dataProvider'=>$updatedOffers,

										'gridID'=>'updated-offers-grid'),false,true);

			}

			Yii::app()->end();

		}

		if($_GET['ajax'] == 'starred-offers-grid'){

			if($model->client == Yii::app()->user->getId()){

				$starredOffers=Serviceoffer::model()->searchStarredOfferByOrder($model->id);

				$this->renderPartial('/serviceoffer/offergrid',array(	'dataProvider'=>$starredOffers,

										'isClient'=>1,

										'unlocked' => $model->unlocked,

										'gridID'=>'starred-offers-grid'),false,true);

			}

			Yii::app()->end();

		}

		if($_GET['ajax'] == 'offers-grid'){

			$offersMade=Serviceoffer::model()->searchOfferByOrder($model->id);

			$this->renderPartial('/serviceoffer/offergrid',array(	'dataProvider'=>$offersMade,

									'isClient'=>1,

									'unlocked' => $model->unlocked,

									'gridID'=>'offers-grid'),false,true);

			Yii::app()->end();

		}

	}

}

....



Please note that when I removed the above code from the controller I still get the same problem.

/serviceoffer/offergrid.php




$this->widget('zii.widgets.grid.CGridView', array(

	'id'=>$gridID,

	'dataProvider'=>$dataProvider,

	'ajaxUpdate'=>true,

	'pager'=>array('class'=>'CLinkPager',

					'header'=>'',

					'maxButtonCount'=>6,

					'prevPageLabel'=>'< Prev',

	),

	'columns'=>$columns,

	'showTableOnEmpty'=>true,

	'emptyText'=>$emptyText,

));

Thanks.