yii2中的分页按钮限制

时间:2015-12-01 00:30:43

标签: php button pagination yii2 limit

我需要在gridview分页中只显示3个元素,然后在按钮分页中显示3个按钮,但按钮动态变化。

示例按钮分页:

[1]-2-3...

点击第二个元素

[2]-3-4...

我的代码:

   
public function search($params)
{
    $query = Area::find();

    $dataProvider = new ActiveDataProvider([
        'query' => $query,
        'pagination' => [
            'pageSize' => 3,
        ],
    ]);

谢谢!

1 个答案:

答案 0 :(得分:10)

您可以使用pager属性

在gridview中执行此操作
     <?= GridView::widget([
    'dataProvider' => $dataProvider,
    'summaryOptions' => ['class' =>'dfenx_pagination_summary',],
    'pager' => ['options' => ['class' => 'pagination pull-right']],
    'filterModel' => $searchModel,
    'pager' => [
        'maxButtonCount'=>3,    // Set maximum number of page buttons that can be displayed
        ],
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
      ..........

这是寻呼机可用的选项

    'pager' => [
        'options'=>['class'=>'pagination'],   // set clas name used in ui list of pagination
        'prevPageLabel' => 'Previous',   // Set the label for the "previous" page button
        'nextPageLabel' => 'Next',   // Set the label for the "next" page button
        'firstPageLabel'=>'First',   // Set the label for the "first" page button
        'lastPageLabel'=>'Last',    // Set the label for the "last" page button
        'nextPageCssClass'=>'next',    // Set CSS class for the "next" page button
        'prevPageCssClass'=>'prev',    // Set CSS class for the "previous" page button
        'firstPageCssClass'=>'first',    // Set CSS class for the "first" page button
        'lastPageCssClass'=>'last',    // Set CSS class for the "last" page button
        'maxButtonCount'=>10,    // Set maximum number of page buttons that can be displayed
        ],