简体   繁体   English

Yii CGridview Pagination renderpartial

[英]Yii CGridview Pagination renderpartial

I'm currently rendering 3 CGridviews in my view, all using "renderPartial" and the same php file. 我目前正在我的视图中渲染3个CGridviews,全部使用“renderPartial”和相同的php文件。 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). 这种方法很好,除了使用分页时,用户选择另一页结果,它会将所有CGridviews移动到该页面(如果可以的话)。 I'm not sure why this is happening or how to fix it. 我不确定为什么会发生这种情况或如何解决它。

I tried this approach post on Yii forms , and it does fix the pagination of the CGridViews, but breaks my ajax functions and css styles. 在Yii表单上尝试了这个方法的帖子 ,它确实修复了CGridViews的分页,但是打破了我的ajax函数和css样式。 See below for an image of this occurring. 请参阅下面的图像。

Here is the CGridView Template 这是CGridView模板

<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',
    ),
));
?>

Here are the "RenderPartial" statements inside my view: 以下是我视图中的“RenderPartial”语句:

<div class="col-md-12 col-sm-12 col-xs-12" style="margin-bottom:60px;">
<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>
</div>

This is what is currently happening: 这是目前正在发生的事情: 在此输入图像描述

And this is what happens when I add "false, true" to my "RenderPartial" statements like the Yii answer: 这就是当我将“false,true”添加到我的“RenderPartial”语句(如Yii答案)时会发生的情况: 在此输入图像描述

Thanks in advance for the help, I'm really lost on this issue. 在此先感谢您的帮助,我真的迷失在这个问题上。

UPDATE For reference, I also asked this question here on the Yii forms, as I find SO has much better response time, but the Yii forms have the concentrated community. 更新的参考,我也问过这个问题在这里就Yii的形式,我觉得SO具有更好的响应时间,但Yii的形式有集中的社区。

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. 首先,我需要将CGridView的“updateSelector”属性设置为每个表的自定义页面选择器。

Secondly, I needed to set the "pageVar" in my "dataProvider" to match the selector. 其次,我需要在“dataProvider”中设置“pageVar”以匹配选择器。

Here is a static example of this to make it as clear as possible. 这是一个静态的例子,使其尽可能清晰。

DataProvider: DataProvider的:

new CArrayDataProvider($data, array(
        'sort'=>array(
            'attributes'=>array(
                'Organization',
                'Roles',
            ),
        ),
        'pagination'=>array(
            'pageSize'=>10,
            'pageVar'=>'custom-page-selector', //page selector
        ),
    ));

CGridView: CGridView:

<?php 
$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>$title .'-grid',
    '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! 希望这有助于未来的人!

if they all react on one of paginations click, it's probably because you named all your grid views with the same name(/id) and it's a matter of conflicted IDs, 如果他们都对其中一个分页点击做出反应,那可能是因为你用相同的名字(/ id)命名了你所有的网格视图,这是一个有冲突的ID的问题,

that's all 就这样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM