Custom pagination template

I currently have this:

    First Prev Next Last

but I want:

First Prev 2 of 15 pages Next Last

Is there a way to insert the 2 of 15 pages in there.

Of course they would be variable, like $currentpage, $maxpage.

I think you have to write your own link pager widget.

The standard LinkPager renders only a set of link buttons and no static text is rendered. It doesn’t have a template. Check the source code of LinkPager, and you’ll get some idea to satisfy your needs.

@ softark

That worked, just before $this->nextPageLabel I inserted:

$buttons[] = " page " . $this->getCurrent() . " of " . $this->getTotal() . " ";

I added two methods:

    protected function getCurrent()
       $currentPage = $this->pagination->getPage(); 
       return $currentPage + 1;
    protected function getTotal()
       $pageCount = $this->pagination->getPageCount();
       return $pageCount;

For some reason, 0 was showing, I had to add a 1.

Any idea why $currentPage = $this->pagination->getPage(); return a 0 on first page?

1 Like

It’s by design. Pagination::$page is a zero-based number.$page-detail

@ softark All working great now.

Is it possible to use Yii2 pagination outside of yii2, or would it be too big a hassle?

Well, I think it’s possible to use Yii2 LinkPager with Pagination (and most probably with DataProvider) outside of a Yii2 app.

Guide > Special Topics > Working with Third-Party Code > Using Yii in Third-Party Systems

But I’m not sure if it’s very easy or convenient.