Can't use ajax pagination with CGirdView

Hi, everybody.

I try to get pagination in my CGridView. Pagination works ok but it doesn’t have ajax.

When i try it in other project, it’s ok.

i recognize that the url of pagination button doesn’t have parameter ajax.

my pagination is: /baongan/transaction/index?NhatKi_page=2 (and it’s GET request)

other is: /demo/department/admin?ajax=department-grid&Department_page=2 (and it’s POST request)

and i also can’t use ajax with dropdownlist.

how can i fix it? (something wrong with my project or config)

help me, please. (sorry about my bad english)

my controller:




public function actionIndex()

	{

            $model = new NhatKi('search'); 

            $this->render('index',array('model'=>$model));

	}



my view:




<?php

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

            'id'=>'nhat-ki-grid',

            'dataProvider'=>$model->search(),

            'ajaxUpdate'=>true,   

            //'filter'=>$model,

            

            'columns'=>array(

		'maGD',

                'ngayGD',

                'gioGD',

                'maLoaiGD0.tenLoaiGD',

                'idDT0.tenDoiTac',

		'soTien',

                'maTT0.tenTT',

	),

        )); ?>



my model:




public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('idNK',$this->idNK);

		$criteria->compare('maGD',$this->maGD);

		$criteria->compare('maTT',$this->maTT);

		$criteria->compare('maTK',$this->maTK);

		$criteria->compare('maLoaiGD',$this->maLoaiGD);

		$criteria->compare('soTien',$this->soTien);

		$criteria->compare('ngayGD',$this->ngayGD,true);

		$criteria->compare('gioGD',$this->gioGD,true);

		$criteria->compare('idDT',$this->idDT);

		$criteria->compare('soNgayTamGiu',$this->soNgayTamGiu);

		$criteria->compare('diaChiNhanHang',$this->diaChiNhanHang,true);

		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

                        'pagination'=>array(

                                'pageSize'=> 10,

                        ),

		));

	}



Check the console tab of your firebug, there must be some javascript error blocking the page to execute the ajax call

Thanks Gustavo but there are nothing in my firebug console (no error).

My problem is when pagination create button, the parameter ajax doesn’t appear, so it can’t call ajax.

how can i solve it?

This is ajax script in my firebug.




<script type="text/javascript">

/*<![CDATA[*/

jQuery(function($) {

jQuery('#nhat-ki-grid').yiiGridView({'ajaxUpdate':['1','nhat-ki-grid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'items','selectableRows':1,'pageVar':'NhatKi_page'});

});

/*]]>*/

</script>



any ideas?

Now I realize that if i use the first layout (layout when you create new Yii project), i can use ajax pagination.

but if i use my own layout, i can’t use ajax pagination.

This is my own layout:




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

  <title>Thương mại điện tử</title>

  

  <!-- Framework CSS -->

      <!-- blueprint CSS framework -->

       <link rel="stylesheet" type="text/css" href="<?php echo Html::cssUrl('screen.css') ?>" media="screen, projection" />

    <link rel="stylesheet" type="text/css" href="<?php echo Html::cssUrl('print.css') ?>" media="print" />

    <!--[if lt IE 8]>

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/ie.css" media="screen, projection" />

    <![endif]-->


    <link rel="stylesheet" type="text/css" href="<?php echo Html::cssUrl('main.css') ?>" />

    <link rel="stylesheet" type="text/css" href="<?php echo Html::cssUrl('form.css') ?>" />

    <!--[if IE]><link rel="stylesheet" href="blueprint/ie.css" type="text/css" media="screen, projection" /><![endif]-->

    

</head>

<body>

      

    <div id="header" >

      <?php include("menu_header.php");?>

    </div>

    <br />

    <br />

    <?php echo $content; ?>

    <hr />


    <div id="footer" class="container">

        <span class="quiet">Copyright &copy; 2011</span><br/>  

        <span class="quiet">Designed by HPL</span>

    </div>

    

    

</body>

</html> 



and this is the first layout:




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <meta name="language" content="en" />


    <!-- blueprint CSS framework -->

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css" media="screen, projection" />

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/print.css" media="print" />

    <!--[if lt IE 8]>

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/ie.css" media="screen, projection" />

    <![endif]-->


    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" />

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/form.css" />


    <title><?php echo CHtml::encode($this->pageTitle); ?></title>

</head>


<body>


<div class="container" id="page">


    <div id="header">

        <div id="logo"><?php echo CHtml::encode(Yii::app()->name); ?></div>

    </div><!-- header -->


    <div id="mainmenu">

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

            'items'=>array(

                array('label'=>'Home', 'url'=>array('/site/index')),

                array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),

                array('label'=>'transaction', 'url'=>array('/transaction/index')),

                array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),

                array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)

            ),

        )); ?>

    </div><!-- mainmenu -->

    <?php if(isset($this->breadcrumbs)):?>

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

            'links'=>$this->breadcrumbs,

        )); ?><!-- breadcrumbs -->

    <?php endif?>


    <?php echo $content; ?>


    <div id="footer">

        Copyright &copy; <?php echo date('Y'); ?> by My Company.<br/>

        All Rights Reserved.<br/>

        <?php echo Yii::powered(); ?>

    </div><!-- footer -->


</div><!-- page -->


</body>

</html> 



who can help me? Please.

Hi,

try to set CGridView::ajaxUpdate to null (or comment it out as null is its default value).

Ref: http://www.yiiframework.com/doc/api/1.1/CGridView#ajaxUpdate-detail

Thanks all.

I solved my problem.

That’s JQuery conflict.

Yii also includes JQuery library.

So if you used Jquery plugin, you should not include JQuery library agian to avoid conflict.

Thanks all.

I solved my problem.

That’s JQuery conflict.

Yii also includes JQuery library.

So if you used Jquery plugin, you should not include JQuery library again to avoid conflicting.