Clistview With Ajax Pagination

Hi all,

I have page with CListView with pagination, but clicking on pagination link I do not want to reload all page, but to reload only

CListView using ajax. How can I do this? Please give ref to decision.

  1. Create separate partial file for the CListView widget:

_widget.php:


<?php $this->widget('zii.widgets.CListView', array(

	'dataProvider'=>$dataProvider,

	'itemView'=>'_item',

)); ?>

  1. Put link to the partial file in your view file:

index.php:


<?php echo $this->renderPartial('_widget', array('dataProvider'=>$dataProvider)); ?>

  1. Create your controller action like this:

NewsController.php:


public function actionIndex()

{

	$dataProvider = new CActiveDataProvider('News');

	

	// handle ajax pagination (prevent outputting entire page)

	if(Yii::app()->request->isAjaxRequest && isset($_GET['ajax']))

	{

		$this->renderPartial('_widget', array('dataProvider'=>$dataProvider));

		

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

	}

	

	$this->render('index', array(

		'dataProvider'=>$dataProvider,

	));

}

I tried to make it your way : firstly the generated pagination has menu items as links to other

pages with parameters based of request parameters of the dataProvider. So clicking on paginations menu item any way goes away.

Please url to working example.

I don’t understand. Can you post your code?

EDIT: Maybe you need to do something like this:

ProductController.php:


public function actionIndex()

{

        $product = new Product('refine');

	

        // searchProducts() function returns a CActiveDataProvider;

	$dataProvider = $product->searchProducts();

        

        // handle ajax pagination (prevent outputting entire page)

        if(Yii::app()->request->isAjaxRequest && isset($_GET['ajax']))

        {

                // this will handle get parameters within the pager links

		if(isset($_GET['Product']))

		{

			$product->attributes = $_GET['Product'];

		}

		

		// searchProducts() function returns a CActiveDataProvider;

		$dataProvider = $product->searchProducts();

		

		$this->renderPartial('_widget', array('dataProvider'=>$dataProvider));

                

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

        }

        

        $this->render('index', array(

                'dataProvider'=>$dataProvider,

        ));

}

by default CListView uses ajax to load the next listView page although on the server it does render the full view it does some magic on client-side to hide that from the user

That is just what I do not see that CListView uses ajax for navigation for other pages.

I use code like :


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

	'dataProvider'=>$dataProvider,

	'ajaxUpdate'=>true,

	'ajaxUrl'=>array($this->getRoute()),

	'itemView'=>'//_blog_view_item',

	'emptyText'=>'No Blogs',

	'enablePagination'=>true,

));

But in any case links of paginations menu are not JS/ajax but usual links, which reopens all page

could be javascript error check your console it happens in some cases