user pagination
This commit is contained in:
parent
9fb72b7840
commit
0459ed561c
@ -12,6 +12,7 @@ use app\tables\columns\UserEditActionColumn;
|
|||||||
use app\tables\columns\UserViewActionColumn;
|
use app\tables\columns\UserViewActionColumn;
|
||||||
use Exception;
|
use Exception;
|
||||||
use http\Message;
|
use http\Message;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Itguild\Tables\ListJsonTable;
|
use Itguild\Tables\ListJsonTable;
|
||||||
use Itguild\Tables\ViewJsonTable;
|
use Itguild\Tables\ViewJsonTable;
|
||||||
use JetBrains\PhpStorm\NoReturn;
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
@ -59,11 +60,11 @@ class UserController extends Controller{
|
|||||||
/**
|
/**
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function actionIndex(): void
|
public function actionIndex($page_id = 1): void
|
||||||
{
|
{
|
||||||
$users = User::all();
|
$users = User::all();
|
||||||
|
|
||||||
$this->cgView->render("user/index.php", ['users' => $users]);
|
$this->cgView->render("user/index.php", ['users' => $users, 'page_id' => $page_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
1
rout.php
1
rout.php
@ -10,6 +10,7 @@ App::$collector->get('/example', [MainController::class, 'actionExample']);
|
|||||||
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
App::$collector->group(["prefix" => "admin"], function (RouteCollector $router){
|
||||||
App::$collector->group(["prefix" => "user"], callback: function (RouteCollector $router){
|
App::$collector->group(["prefix" => "user"], callback: function (RouteCollector $router){
|
||||||
App::$collector->get('/', [\app\controllers\UserController::class, 'actionIndex']);
|
App::$collector->get('/', [\app\controllers\UserController::class, 'actionIndex']);
|
||||||
|
App::$collector->get('/page/{page_id}', [\app\controllers\UserController::class, 'actionIndex']);
|
||||||
App::$collector->get('/create', [\app\controllers\UserController::class, 'actionCreate']);
|
App::$collector->get('/create', [\app\controllers\UserController::class, 'actionCreate']);
|
||||||
App::$collector->post("/", [\app\controllers\UserController::class, 'actionAdd']);
|
App::$collector->post("/", [\app\controllers\UserController::class, 'actionAdd']);
|
||||||
App::$collector->get('/{id}', [\app\controllers\UserController::class, 'actionView']);
|
App::$collector->get('/{id}', [\app\controllers\UserController::class, 'actionView']);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Illuminate\Database\Eloquent\Collection $users
|
* @var \Illuminate\Database\Eloquent\Collection $users
|
||||||
|
* @var int $page_id
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use app\models\User;
|
use app\models\User;
|
||||||
@ -12,7 +13,9 @@ use Itguild\Tables\ListJsonTable;
|
|||||||
use kernel\IGTabel\btn\PrimaryBtn;
|
use kernel\IGTabel\btn\PrimaryBtn;
|
||||||
use kernel\IGTabel\ListJsonTableEloquentCollection;
|
use kernel\IGTabel\ListJsonTableEloquentCollection;
|
||||||
|
|
||||||
$dataProvider = new ListJsonTableEloquentCollection($users, [
|
$perPage = 3;
|
||||||
|
$chunks = $users->forPage($page_id, $perPage);
|
||||||
|
$dataProvider = new ListJsonTableEloquentCollection($chunks, [
|
||||||
'model' => User::class,
|
'model' => User::class,
|
||||||
'perPage' => 5,
|
'perPage' => 5,
|
||||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||||
@ -23,8 +26,8 @@ $table->beforePrint(function () {
|
|||||||
return PrimaryBtn::create("Создать", "/admin/user/create")->fetch();
|
return PrimaryBtn::create("Создать", "/admin/user/create")->fetch();
|
||||||
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
|
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
|
||||||
});
|
});
|
||||||
$table->afterPrint(function () use ($users) {
|
$table->afterPrint(function () use ($page_id, $users, $perPage) {
|
||||||
$pagination = new \Itguild\Tables\Pagination($users->count(), 5, 1, "/admin/user/");
|
$pagination = new \Itguild\Tables\Pagination($users->count(), $perPage, $page_id, "/admin/user/page");
|
||||||
$pagination->create();
|
$pagination->create();
|
||||||
return $pagination->fetch();
|
return $pagination->fetch();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user