在yii

时间:2016-10-07 11:18:58

标签: php yii pagination

我想通过CGridView以分页显示数据..

问题在于数据提供者是一个数组,而不是CArrayDataProvider或CDataProvider ..

如果dataprovider是一个数组,如何添加分页,如下所示

$this->widget('zii.widgets.grid.CGridView', array(
            'id'=>'family-record-grid',
            'dataProvider'=>$arr[1],

            'enableSorting' => false,
            'columns'=>
            array()
          ));

1 个答案:

答案 0 :(得分:0)

您可以在视图文件中尝试 CGridView

$this->widget('zii.widgets.grid.CGridView', array(
            'id'=>'family-record-grid',
            'dataProvider'=>$model->search(),
            'afterAjaxUpdate'   => 'function(){}',
            'htmlOptions'       => array('class' => 'form-inline', 'role' => 'grid'),
            'ajaxUrl'           => Yii::app()->createUrl('controllername/actioname'), 
            'ajaxUpdate'        => true,
            'enablePagination'  => true,
            "summaryText"       => true,
            'itemsCssClass'     => 'responsive dataTable', // Item CSS Class
            "template"          => "{items}\n{summary}{pager}",
            "summaryText"       => "Showing {start} to {end} of {count} entries",
            'pagerCssClass'     => '', // Page CSS Class
            'pager'             => array(
                'class' => 'CLinkPager',
                'maxButtonCount'    => 5,
                'nextPageLabel'     => 'Next',
                'prevPageLabel'     => 'Prev',
                'firstPageLabel'    => 'First',
                'lastPageLabel'     => 'Last',
            ),
            'selectableRows'    => 2,
            'enableSorting' => false,
            'columns'=>array()
            )
);