pagination fix
This commit is contained in:
parent
647fe34d11
commit
f5f6504545
@ -10,6 +10,7 @@
|
|||||||
"perPage": "5",
|
"perPage": "5",
|
||||||
"currentPage": "1",
|
"currentPage": "1",
|
||||||
"total": 10,
|
"total": 10,
|
||||||
|
"prefix": "/page",
|
||||||
"params": {"class": "table table-bordered", "border": "1"}
|
"params": {"class": "table table-bordered", "border": "1"}
|
||||||
},
|
},
|
||||||
"data": [
|
"data": [
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Itguild\Tables;
|
namespace Itguild\Tables;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
use Itguild\Tables\ActionColumn\ActionColumn;
|
use Itguild\Tables\ActionColumn\ActionColumn;
|
||||||
use Itguild\Tables\ActionColumn\DeleteActionColumn;
|
use Itguild\Tables\ActionColumn\DeleteActionColumn;
|
||||||
use Itguild\Tables\ActionColumn\EditActionColumn;
|
use Itguild\Tables\ActionColumn\EditActionColumn;
|
||||||
@ -170,6 +171,9 @@ class ListJsonTable
|
|||||||
return $actions;
|
return $actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public function create(): void
|
public function create(): void
|
||||||
{
|
{
|
||||||
$this->setActions();
|
$this->setActions();
|
||||||
@ -192,6 +196,9 @@ class ListJsonTable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public function endTable(): void
|
public function endTable(): void
|
||||||
{
|
{
|
||||||
$this->html .= "</table>";
|
$this->html .= "</table>";
|
||||||
@ -199,12 +206,14 @@ class ListJsonTable
|
|||||||
$this->html .= $hookAfter($this->data['meta']);
|
$this->html .= $hookAfter($this->data['meta']);
|
||||||
|
|
||||||
if ($this->pagination){
|
if ($this->pagination){
|
||||||
$pagination = new Pagination(
|
$options = [
|
||||||
$this->data['meta']['total'],
|
'countItem' => $this->data['meta']['total'],
|
||||||
$this->data['meta']['perPage'],
|
'perPage' => $this->data['meta']['perPage'],
|
||||||
$this->data['meta']['currentPage'],
|
'currentPage' => $this->data['meta']['currentPage'],
|
||||||
$this->baseUrl
|
'baseUrl' => $this->baseUrl,
|
||||||
);
|
'prefix' => $this->data['meta']['prefix'],
|
||||||
|
];
|
||||||
|
$pagination = new Pagination($options);
|
||||||
$pagination->create();
|
$pagination->create();
|
||||||
$this->html .= $pagination->fetch();
|
$this->html .= $pagination->fetch();
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
namespace Itguild\Tables;
|
namespace Itguild\Tables;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use http\Message;
|
||||||
|
|
||||||
class Pagination
|
class Pagination
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -14,13 +17,21 @@ class Pagination
|
|||||||
|
|
||||||
private string $baseUrl;
|
private string $baseUrl;
|
||||||
|
|
||||||
public function __construct($countItem, $perPage, $currentPage, $baseUrl)
|
// public function __construct($countItem, $perPage, $currentPage, $baseUrl)
|
||||||
// public function __construct(int $countItem, array $params, string $baseUrl)
|
|
||||||
|
/**
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function __construct(array $options,)
|
||||||
{
|
{
|
||||||
$this->countItem = $countItem;
|
if (!$options['countItem']) {
|
||||||
$this->perPage = $perPage;
|
throw new Exception(message: "countItem is not valid");
|
||||||
$this->currentPage = $currentPage;
|
}
|
||||||
$this->baseUrl = $baseUrl;
|
$this->countItem = $options['countItem'];
|
||||||
|
$this->perPage = $options['perPage'] ?? 10;
|
||||||
|
$this->currentPage = $options['currentPage'] ?? 1;
|
||||||
|
$this->baseUrl = $options['baseUrl'];
|
||||||
|
$this->baseUrl .= $options['prefix'] ?? '/page';
|
||||||
|
|
||||||
$this->countPages = ceil($this->countItem / $this->perPage);
|
$this->countPages = ceil($this->countItem / $this->perPage);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user