Answer the question
In order to leave comments, you need to log in
How to make automatic adding buttons first page, last page in pagination?
Tables are displayed on the pages through GridView::widget, so that everyone does not prescribe
'pager' => [
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
],
public function getLinks($absolute = false)
{
$currentPage = $this->getPage();
$pageCount = $this->getPageCount();
$links = [
Link::REL_SELF => $this->createUrl($currentPage, null, $absolute),
];
if ($currentPage > 0) {
$links[self::LINK_FIRST] = $this->createUrl(0, null, $absolute);
$links[self::LINK_PREV] = $this->createUrl($currentPage - 1, null, $absolute);
}
if ($currentPage < $pageCount - 1) {
$links[self::LINK_NEXT] = $this->createUrl($currentPage + 1, null, $absolute);
$links[self::LINK_LAST] = $this->createUrl($pageCount - 1, null, $absolute);
}
return $links;
}
Answer the question
In order to leave comments, you need to log in
no need to call any methods because it will be a crutch solution.
In a LinkPager (which uses a GridView), by default the firstPageLabel and lastPageLabel properties are set to false - i.e. do not display these buttons.
If you want to get rid of code duplication, you can simply create your own GridView class that inherits from the standard one and change the default values of the corresponding properties in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question