mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Adjust pagination to match design
This commit is contained in:
parent
d135c13c94
commit
929182f818
@ -83,25 +83,57 @@ class GridFieldPaginator implements GridField_HTMLProvider, GridField_DataManipu
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getHTMLFragments($gridField) {
|
public function getHTMLFragments($gridField) {
|
||||||
$forTemplate = new ArrayData(array());
|
// Figure out which page and record range we're on
|
||||||
$forTemplate->Fields = new ArrayList;
|
|
||||||
|
|
||||||
$countList = clone $gridField->List;
|
$countList = clone $gridField->List;
|
||||||
$totalRows = $countList->limit(null)->count();
|
$totalRows = $countList->limit(null)->count();
|
||||||
$totalPages = ceil($totalRows/$this->itemsPerPage);
|
$totalPages = ceil($totalRows/$this->itemsPerPage);
|
||||||
for($idx=1; $idx<=$totalPages; $idx++) {
|
$firstShownRecord = ($this->currentPage - 1) * $this->itemsPerPage + 1;
|
||||||
if($idx == $this->currentPage) {
|
$lastShownRecord = $this->currentPage * $this->itemsPerPage;
|
||||||
$field = new LiteralField('pagination_'.$idx, $idx);
|
if($lastShownRecord > $totalRows)
|
||||||
} else {
|
$lastShownRecord = $totalRows;
|
||||||
$field = new GridField_Action($gridField, 'pagination_'.$idx, $idx, 'paginate', $idx);
|
|
||||||
$field->addExtraClass('ss-gridfield-button');
|
|
||||||
}
|
|
||||||
|
|
||||||
$forTemplate->Fields->push($field);
|
|
||||||
}
|
// Ten pages back button
|
||||||
if(!$forTemplate->Fields->Count()) {
|
$prev10PageNum = $this->currentPage - 10 <= 1 ? 1 : $this->currentPage - 10;
|
||||||
return array();
|
$prev10Page = new GridField_Action($gridField, 'pagination_prev10', '-10', 'paginate', 1);
|
||||||
}
|
$prev10Page->addExtraClass('ss-gridfield-prev10page');
|
||||||
|
if($this->currentPage == 1)
|
||||||
|
$prev10Page = $prev10Page->performDisabledTransformation();
|
||||||
|
|
||||||
|
// Previous page button
|
||||||
|
$previousPageNum = $this->currentPage <= 1 ? 1 : $this->currentPage - 1;
|
||||||
|
$previousPage = new GridField_Action($gridField, 'pagination_prev', 'Previous', 'paginate', $previousPageNum);
|
||||||
|
$previousPage->addExtraClass('ss-gridfield-previouspage');
|
||||||
|
if($this->currentPage == 1)
|
||||||
|
$previousPage = $previousPage->performDisabledTransformation();
|
||||||
|
|
||||||
|
// Next page button
|
||||||
|
$nextPageNum = $this->currentPage >= $totalPages ? $totalPages : $this->currentPage + 1;
|
||||||
|
$nextPage = new GridField_Action($gridField, 'pagination_next', 'Next', 'paginate', $nextPageNum);
|
||||||
|
$nextPage->addExtraClass('ss-gridfield-nextpage');
|
||||||
|
if($this->currentPage == $totalPages)
|
||||||
|
$nextPage = $nextPage->performDisabledTransformation();
|
||||||
|
|
||||||
|
// Ten pages forward button
|
||||||
|
$next10PageNum = $this->currentPage + 10 >= $totalPages ? $totalPages : $this->currentPage + 10;
|
||||||
|
$next10Page = new GridField_Action($gridField, 'pagination_next10', '+10', 'paginate', $next10PageNum);
|
||||||
|
$next10Page->addExtraClass('ss-gridfield-next10page');
|
||||||
|
if($this->currentPage == $totalPages)
|
||||||
|
$next10Page = $next10Page->performDisabledTransformation();
|
||||||
|
|
||||||
|
|
||||||
|
// Render in template
|
||||||
|
$forTemplate = new ArrayData(array(
|
||||||
|
'Previous10Page' => $prev10Page,
|
||||||
|
'PreviousPage' => $previousPage,
|
||||||
|
'CurrentPageNum' => $this->currentPage,
|
||||||
|
'NumPages' => $totalPages,
|
||||||
|
'NextPage' => $nextPage,
|
||||||
|
'Next10Page' => $next10Page,
|
||||||
|
'FirstShownRecord' => $firstShownRecord,
|
||||||
|
'LastShownRecord' => $lastShownRecord,
|
||||||
|
'NumRecords' => $totalRows
|
||||||
|
));
|
||||||
return array(
|
return array(
|
||||||
'footer' => $forTemplate->renderWith('GridFieldPaginator_Row', array('Colspan'=>count($gridField->getColumns()))),
|
'footer' => $forTemplate->renderWith('GridFieldPaginator_Row', array('Colspan'=>count($gridField->getColumns()))),
|
||||||
);
|
);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="bottom-all" colspan="$Colspan">
|
<td class="bottom-all" colspan="$Colspan">
|
||||||
<% control Fields %>
|
$Previous10Page $PreviousPage Page $CurrentPageNum of $NumPages $NextPage $Next10Page
|
||||||
$Field
|
|
||||||
<% end_control %>
|
View $FirstShownRecord - $LastShownRecord of $NumRecords
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
Loading…
x
Reference in New Issue
Block a user