-
Notifications
You must be signed in to change notification settings - Fork 18
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
Comments
Thanks for the info, I'll look into this issue soon. By the way, glad that you found a way around this. |
add this before class PageSize
|
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. |
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:
|
@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 |
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 thesizes
array too.The text was updated successfully, but these errors were encountered: