组件
Pagination Blade component
简介
分页组件只能在 Livewire Blade 视图中使用。它可以渲染分页链接列表:
use App\Models\User;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class ListUsers extends Component
{
// ...
public function render(): View
{
return view('livewire.list-users', [
'users' => User::query()->paginate(10),
]);
}
}
<x-filament::pagination :paginator="$users" />
或者,你可以使用简单分页或光标分页,它只会渲染“上一页”和“下一页”按钮:
use App\Models\User;
User::query()->simplePaginate(10)
User::query()->cursorPaginate(10)
允许用户自定义每页项目数
你可以通过将一个选项数组传递给 page-options
属性来允许用户自定义每页项目数。你也必须定义一个 Livewire 属性来存储用户的选择:
use App\Models\User;
use Illuminate\Contracts\View\View;
use Livewire\Component;
class ListUsers extends Component
{
public int | string $perPage = 10;
// ...
public function render(): View
{
return view('livewire.list-users', [
'users' => User::query()->paginate($this->perPage),
]);
}
}
<x-filament::pagination
:paginator="$users"
:page-options="[5, 10, 20, 50, 100, 'all']"
:current-page-option-property="perPage"
/>
显示指向首页和末页的链接
极值链接(Extreme link)是指指向首页和末页的链接。你可以通过将 extreme-links
属性传递给组件来添加它们:
<x-filament::pagination
:paginator="$users"
extreme-links
/>
Edit on GitHubStill need help? Join our Discord community or open a GitHub discussion