Cgridview Pagination Renderpartial

Hello Everybody,

I’m currently rendering 3 CGridviews in my view, all using “renderPartial” and the same php file. This works fine, except for when using pagination, and the user selects another page of results, it moves all the CGridviews to that page (if they can). I’m not sure why this is happening or how to fix it. Here is an image of what this looks like:

5626

before.jpg

Here is the CGridView Template


<div class="row btn-row">

<h2 class="admin-h1"><?php echo $title; ?></h2>

<div class="btn-block-div">

    <button class="btn addOrgBtn" id="<?php echo $title; ?>">Add</button>

</div>

</div>

<?php 

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

    'id'=>$title .'-table',

    'dataProvider'=>$dataProvider,

    'selectableRows'=>1,

    'hideHeader'=>true,

    'selectionChanged'=>'viewRoles',

    'columns'=>array(

        array(

            'header'=>'Name',

            'name'=>'Organization',

        ),

        'Roles',

    ),

));

?>

and here are the three "RenderPartial" statements inside of my view




<div class="col-md-4 col-sm-4 col-xs-12" id="School-grid">

    <?php echo $this->renderPartial('_roleTable', array('title'=>'School', 'model'=>$model, 'dataProvider'=>$schoolItems)); ?>

</div>

<div class="col-md-4 col-sm-4 col-xs-12" id="Classroom-grid">

    <?php echo $this->renderPartial('_roleTable', array('title'=>'Classroom', 'model'=>$model, 'dataProvider'=>$classroomItems)); ?>

</div>

<div class="col-md-4 col-sm-4 col-xs-12" id="Shared-grid">

    <?php echo $this->renderPartial('_roleTable', array('title'=>'Shared', 'model'=>$model, 'dataProvider'=>$sharedItems)); ?>

</div>

If I add the parameters (false, true) to the end of the “RenderPartial” statements, it fixes the pagination problem, but all of my custom JS and the CSS styling’s are gone. Here is an image of what this looks like:

5625

after.jpg

I’m not sure what’s causing this issue, as inspecting the page in both cases produces identical widget and JS code. Thank you in advance for the help, I’m really looking forward to solving this.

The problem was a combination of things.

First off, I needed to set the "updateSelector" attribute of CGridView to a custom page selector for each table.

Secondly, I needed to set the "pageVar" in my "dataProvider" to match the selector.

Here is a static example of this to make it as clear as possible.

DataProvider:


new CArrayDataProvider($data, array(

        'sort'=>array(

            'attributes'=>array(

                'Organization',

                'Roles',

            ),

        ),

        'pagination'=>array(

            'pageSize'=>10,

            'pageVar'=>'custom-page-selector', //page selector

        ),

    ));

CGridView:




<?php 

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

    'id'=>$title .'-table',

    'dataProvider'=>$dataProvider,

    'selectableRows'=>1,

    'updateSelector'=>'custom-page-selector', //update selector

    'columns'=>array(

        array(

            'header'=>'Name',

            'name'=>'Organization',

        ),

        'Roles',

    ),

));

Hope this helps someone in the future!

Hi,

Just set it jqyery.js false when action was start and pass the processOutput.

$cs = Yii::app()->clientScript;

	&#036;cs-&gt;reset();


	&#036;cs-&gt;scriptMap = array(


    	'jquery.js'  =&gt;  false,   // prevent produce jquery.js in additional javascript data


	);