Pagination

hi,

how can you not show pagination if there is only one result page?

iqnev

details about paginations are all in yii/framework/web/CPagination.php

set you default page size and you will be done

workaround (case ListView):




class ListView extends \yii\widgets\ListView {

    

    public function renderPager()

    {

        $pagination = $this->dataProvider->getPagination();

        if ($pagination === false || $this->dataProvider->getCount() <= $pagination->pageSize) {

            return '';

        }

        return parent::renderPager();

}



correction:




 if ($pagination === false || $this->dataProvider->getTotalCount() <= $pagination->pageSize) { 

            return '';

        }



note: getTotalCount()

You did not mention where you are showing the pagination? Is it a ListView or GridView or your own custom widget?

Assuming its a ListView or GridView, if you just do not want to show the pager on the View… just simply set the layout property of the ListView or GridView (to not show the pager). Of course, you need to edit the page size of the output from dataProvider to ensure you have results in one page.




'layout'=>"{summary}\n{items}", // you can add {sorter} if you need



I do not use ListView or GridView in this case … I have a list of items on the page, but when the items are less than the maximum of 1 page pagination again showing pagiing.


 <?=

                    LinkPager::widget([

                        'pagination' => $pages,

                        'options' => [

                            'id' => 'pagination'

                        ],

                        'linkOptions' => [

                            'class' => 'page'

                        ],

                    ]);

                    ?>

Where $pages is items from new Pagination() class.

You could do this probably through a simple hack :)




if ($pages->pageCount > 1) {

    echo LinkPager::widget([

        'pagination' => $pages,

        'options' => [

            'id' => 'pagination'

        ],

        'linkOptions' => [

            'class' => 'page'

        ],

    ]);

}



Okay, but this should not be a matter of mere framework