dougaodi8895 2013-08-28 15:05
浏览 88

分页在Yii Framework中不起作用

I am using Yii Rights modules for ACL where I want pagination for Permissions page.

Following is my code:

In AuthItemController.php

public function actionPermissions() {
        $dataProvider = new RPermissionDataProvider('permissions', array(
                    'pagination' => array(
                        'pageSize' => 10,
                        //'class' => 'CPagination', //showing an error
                        'itemCount' => 32
                        )));

        // Get the roles from the data provider
        $roles = $dataProvider->getRoles();
        $roleColumnWidth = $roles !== array() ? 75 / count($roles) : 0;

        // Initialize the columns
        $columns = array(
            array(
                'name' => 'description',
                'header' => Rights::t('core', 'Item'),
                'type' => 'raw',
                'htmlOptions' => array(
                    'class' => 'permission-column',
                    'style' => 'width:25%',
                ),
            ),
        );

        // Add a column for each role
        foreach ($roles as $roleName => $role) {
            $columns[] = array(
                'name' => strtolower($roleName),
                'header' => $role->getNameText(),
                'type' => 'raw',
                'htmlOptions' => array(
                    'class' => 'role-column',
                    'style' => 'width:' . $roleColumnWidth . '%',
                ),
            );
        }

        $view = 'permissions';
        $params = array(
            'dataProvider' => $dataProvider,
            'columns' => $columns,
        );

        // Render the view
        isset($_POST['ajax']) === true ? $this->renderPartial($view, $params) : $this->render($view, $params);
    }

And in View

$this->widget('bootstrap.widgets.TbGridView', array(
        'type' => 'bordered',
        'dataProvider' => $dataProvider,
        'template' => '{pager}{items}',
        'emptyText' => Rights::t('core', 'No authorization items found.'),
        'htmlOptions' => array('class' => 'grid-view permission-table'),
        'columns' => $columns,
        'pager' => array(
            'header' => '',
            'hiddenPageCssClass' => 'disabled',
            'maxButtonCount' => 3,
            'cssFile' => false,
            'class' => 'CLinkPager',
            'prevPageLabel' => '<i class="icon-chevron-left"></i>',
            'nextPageLabel' => '<i class="icon-chevron-right"></i>',
            'firstPageLabel' => 'First',
            'lastPageLabel' => 'Last',
        ),
        'pagerCssClass' => 'pagination',
    ));

I have already implemented pagination for other pages by using same method but here in rights module its not working. Its not showing any error but also not displaying pagination links/buttons.

  • 写回答

1条回答 默认 最新

  • dongshi3061 2013-09-23 08:58
    关注

    I had the same problem when implementing multiple grids in one page, the solution that worked for me was , I checked the url the grid ajax call,and before update I manipulated the url, and set the correct url and parameters before ajax request!

    like:

    $this->widget('zii.grid.GridView', array(
      'id' => 'group-grid-customers-list-not-scheduled',
      'dataProvider' => $notScheduledVisitedDataProvider ,
      'beforeAjaxUpdate' => '
            function(id , options)
            { 
                options.url = options.url.split("&test=test&");
                options.url = options.url[0] + "&test=test&" + $(".search-form form").serialize(); 
            }',
      'columns' => array(
          'col1',
          'col2',
          'col3',
      ),
    ));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)