Skip to content

Commit 2b31d65

Browse files
author
ethan
committed
pageConfig
1 parent 41ecf0f commit 2b31d65

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Builder.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,16 @@ public function loadDefaultValues($entity = null)
305305

306306
/**
307307
* 分页
308+
* @param int $pageSize 每页数据条数
308309
* @return DataProvider
309310
*/
310-
public function paginate()
311+
public function paginate($pageSize = null)
311312
{
312-
return new DataProvider($this);
313+
$pageConfig = array();
314+
if ($pageSize !== null) {
315+
$pageConfig['pageSize'] = $pageSize;
316+
}
317+
return new DataProvider($this, $pageConfig);
313318
}
314319

315320
/**

src/DataProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ class DataProvider implements \JsonSerializable, \ArrayAccess, \Iterator
1717

1818
private $data;
1919

20+
private $pageConfig = array();
21+
2022
/**
2123
* @param \PFinal\Database\Builder $query
2224
*/
23-
public function __construct($query)
25+
public function __construct($query, array $pageConfig = array())
2426
{
2527
$this->query = $query;
28+
$this->pageConfig = $pageConfig;
2629
}
2730

2831
/**
@@ -43,6 +46,8 @@ public function getPage()
4346

4447
$this->page = Application::$app->make('Leaf\\Pagination');
4548

49+
$this->page->config($this->pageConfig);
50+
4651
$countQuery = clone $this->query;
4752
$this->page->itemCount = $countQuery->count();
4853
}

0 commit comments

Comments
 (0)