Yii: where are first and last navigation buttons?

With displaying pages of results with CGridView, there are page links to navigate to various pages. There are ‘Previous’ and ‘Next’ buttons, but where are ‘First’ and ‘Last’ buttons?

When viewing the source code, you can see these buttons in html code.

After some research, I found out the following facts:

  • these buttons are hidden by default
  • visibility of these buttons are controlled by css

It doesn’t really make sense to hide them by default. It also doesn’t make sense to control the visibility of these buttons via CSS. But that’s how it works at the moment.

Quick way to show the first and last buttons

At the moment, V115, you can quickly show the buttons. Assuming you’re using the default layout.

The css file should be located here: /path/to/web/assets/some random string/pager.css.

Copy this pager.css file to /path/to/web/css. edit this file. Scroll to the very end of the file, and delete as marked:

ul.yiiPager .first,
ul.yiiPager .last
{
    display:none; // delete this line!!
}

Now edit config file, under /path/to/protected/config:

'components' => array(
...
    'widgetFactory' => array(
        'widgets' => array(
            'CLinkPager' => array(
                'cssFile' => '/css/pager.css',
            ),
        ),
    ),
...
),

Now the First and Last button should be displayed.

What about themes?

I have yet found any solutions nor worked out how to set it in config file. If you know the answer, please leave a comment. thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *