Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work for more than 50 items #7

Open
sinaza opened this issue May 15, 2016 · 5 comments
Open

Doesn't work for more than 50 items #7

sinaza opened this issue May 15, 2016 · 5 comments
Labels

Comments

@sinaza
Copy link

sinaza commented May 15, 2016

Thanks for the great work.

For me, displaying more than 50 items per page is not working and it automatically limits itself to 50.

Because of this, and the fact that an "All" option is needed, I've added
if(isset($_GET['per-page'])) $dataProvider->pagination->pageSize = $_GET['per-page'];

inside the actionIndex() which fixes both problems. Oh and I put 'all'=>'All' in the sizes array too.

@nterms
Copy link
Owner

nterms commented May 16, 2016

Thanks for the info, I'll look into this issue soon. By the way, glad that you found a way around this.

@nterms nterms added the bug label May 16, 2016
@alvinux
Copy link

alvinux commented Jul 1, 2016

add this before class PageSize

\Yii::$container->set('yii\data\Pagination', [
   'pageSizeLimit' => [1, 200],
]);

@marekpetras
Copy link

marekpetras commented Nov 21, 2016

Hey,

this is not a bug, its intended pagination limitation that you have to override in the DI container. I extended gridview to include everything by itself:

<?php

namespace app\widgets;

use Yii;
use nterms\pagesize\PageSize;

/**
 * adds a pagesize widget by default to the grid
 */
class GridView extends \yii\grid\GridView
{
    /**
     * @var default filter selector for Pagesize widget
     */
    public $filterSelector = 'select[name="per-page"]';

    /**
     * @var default filter selector for Pagesize widget
     */
    public $layout = "{pagesize}\n{summary}\n{items}\n{pager}";

    /**
     * @var pageSizeLimit for the pagination service
     */
    public $pageSizeLimit = [1,200];

    /**
     * @var defaultPageSize for the pagination service and the Pagesize widget
     */
    public $defaultPageSize = 50;

    /**
     * @inheritdoc
     */
    public function init()
    {
        Yii::$container->set('yii\data\Pagination', [
           'pageSizeLimit' => $this->pageSizeLimit,
           'defaultPageSize' => $this->defaultPageSize,
        ]);

        parent::init();
    }

    /**
     * @inheritdoc
     */
    public function renderSection($name)
    {
        switch ($name) {
            case '{pagesize}':
                return $this->renderPagesize();
            default:
                return parent::renderSection($name);
        }
    }

    /**
     * Renders the pagesize widget.
     * @return string the rendering result
     */
    public function renderPagesize()
    {
        return PageSize::widget(['defaultPageSize' => Yii::$container->get('yii\data\Pagination')->defaultPageSize]);
    }
}

works like a charm.

@LeoZandvliet
Copy link

This issue finally got me on track of the 'misbehaving' gridview! :D

@marekpetras I tried your nice solution but found out I had to add the pagination object to the dataProvider of the GridView to get the pageSizeLimit to work. Probaly because it already exists before GridView->init() is called. Is this correct? The following works for me:

public function init()
{
    Yii::$container->set('yii\data\Pagination', [
           'pageSizeLimit' => $this->pageSizeLimit,
           'defaultPageSize' => $this->defaultPageSize,
    ]);
		
    if($this->dataProvider)
    {
	$this->dataProvider->pagination = ['pageSizeLimit' => $this->pageSizeLimit, 'defaultPageSize' => $this->defaultPageSize];
    }

    parent::init();
}

@marekpetras
Copy link

@LeoZandvliet hm, i dont think i ve ever needed to do any changes to the pagination in my searchmodel or anything, basically, i dont think i ve actually ever touched pagination directly, you are better of modifying it via query parameters as intended. And if for some reason you modify the pagination before you create the gridview, this approach will drop the old pagination and create a new one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants