forked from pgyf/yii2-widget-linkpager
/
LinkPager.php
65 lines (57 loc) · 1.84 KB
/
LinkPager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace liyunfang\pager;
use yii\helpers\Html;
/**
* Description of LinkPager
*
* @author liyunfang <381296986@qq.com>
* @date 2015-09-07
*/
class LinkPager extends \yii\widgets\LinkPager{
const POSITION_LEFT = 'left';
const POSITION_RIGHT = 'right';
/**
* display pageSize
*/
public $showPageSize = true;
/**
* pageSize list
*/
public $pageSizeList = [10, 20, 30, 50];
/**
* drop-down box position
* default is 'right'
*/
public $dropDownPosition = 'right';
private $dropDownOptions = ['class' => 'form-control','style' => 'display: inline-block;width:auto;margin-left:5px;margin-right:5px;margin-top:0px;'];
/**
* Executes the widget.
* This overrides the parent implementation by displaying the generated page buttons.
*/
public function run()
{
if ($this->registerLinkTags) {
$this->registerLinkTags();
}
$leftContent = "";
$rightContent = "";
if($this->showPageSize && $this->pagination->totalCount > 0){
$dropDownList = $this->renderPageDropDownList();
if($this->dropDownPosition == static::POSITION_LEFT){
$leftContent = $dropDownList;
}
else if($this->dropDownPosition == static::POSITION_RIGHT){
$rightContent = $dropDownList;
}
}
echo $leftContent.$this->renderPageButtons().$rightContent;
}
protected function renderPageDropDownList(){
$pageSizeList = [];
foreach ($this->pageSizeList as $value) {
$pageSizeList[$value] = $value;
}
//$linkurl = $this->pagination->createUrl($page);
return Html::dropDownList($this->pagination->pageSizeParam, $this->pagination->getPageSize(), $pageSizeList, $this->dropDownOptions);
}
}