kartik-v / yii2-dynagrid

Turbo charge the Yii 2 GridView with personalized columns, page size, and themes.
http://demos.krajee.com/dynagrid
Other
74 stars 66 forks source link

Correct grid pagination assignment #227

Closed Zdunek closed 2 years ago

Zdunek commented 4 years ago

I try make treegrid and i use $dataProvider->getModels() and dataProvider->setModels($new_models), but, after use $dataProvider->getModels(); pagination in dynagrid stop working. Stop showing pagination, stop working param pageSize and probably other For problem confirmation i tried kartik\grid\GridView and in this view everything working property.

Dynagrid v1.5.1

Edit: Problem is when is not set defaultPageSize in module config. When is set something not 0 problem is solved.

   'dynagrid'=>[
        'class'=>'\kartik\dynagrid\Module',
        'defaultPageSize' => 10,
        // other settings (refer documentation)
    ],
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

davidbaselj commented 3 years ago

I have the same issue as @Zdunek mentioned. When calling $dataProvider->getModels() and dataProvider->setModels($new_models) the pagination is not working.

Even if I set defaultPageSize pagination is still not visible.

davidbaselj commented 3 years ago

I found the solution.

The problem is that in applyPageSize() function in line 1122 of DynaGrid.php $dataProvider->pagination gets overridden.

  protected function applyPageSize()
    {
        if (isset($this->_pageSize) && $this->_pageSize !== '' && $this->allowPageSetting) {
            /** @var \yii\data\BaseDataProvider $dataProvider */
            $dataProvider = $this->gridOptions['dataProvider'];
            if ($dataProvider instanceof ArrayDataProvider) {
                $dataProvider->refresh();
            }
            if ($this->_pageSize > 0) {
                $dataProvider->setPagination(['pageSize' => $this->_pageSize]);    // <======= the line where pagination get's overriden
            } else {
                $dataProvider->setPagination(false);
            }
            if ($dataProvider instanceof SqlDataProvider) {
                $dataProvider->prepare(true);
            }
            $this->gridOptions['dataProvider'] = $dataProvider;
        }
    }

Currently I fixed it with $dataProvider->setPagination(['pageSize' => $this->_pageSize, 'totalCount' => $dataProvider->getTotalCount()]);

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.