Table
Вы просматриваете документацию старой версии MoonShine. Рассмотрите возможность обновления вашего проекта до MoonShine 2.x.
# Основы
Стилизованные таблицы можно создавать с помощью компонента moonshine::table
<x-moonshine::table :columns="[ '#', 'First', 'Last', 'Email' ]" :values="[ [1, fake()->firstName(), fake()->lastName(), fake()->safeEmail()], [2, fake()->firstName(), fake()->lastName(), fake()->safeEmail()], [3, fake()->firstName(), fake()->lastName(), fake()->safeEmail()] ]"/>
| # | First | Last | |
|---|---|---|---|
| 1 | Jamaal | Wilderman | ihill@example.org |
| 2 | Gilbert | Ernser | hettinger.antonietta@example.org |
| 3 | Giovanna | Cruickshank | audie.schoen@example.net |
# Crud режим
Параметр crudMode позволяет дополнительно стилизовать таблицы
<x-moonshine::table :crudMode="true" :columns="[ '#', 'First', 'Last', 'Email' ]" :values="[ [1, fake()->firstName(), fake()->lastName(), fake()->safeEmail()], [2, fake()->firstName(), fake()->lastName(), fake()->safeEmail()], [3, fake()->firstName(), fake()->lastName(), fake()->safeEmail()] ]"/>
| # | First | Last | |
|---|---|---|---|
| 1 | Carolina | Hintz | dereck.schultz@example.org |
| 2 | Kiara | Hickle | gusikowski.simeon@example.net |
| 3 | Stella | Orn | rau.kaelyn@example.net |
# Отсутствие элементов
Параметр notfound позволяет выводить сообщение при отсутствии элементов таблицы
<x-moonshine::table :columns="[ '#', 'First', 'Last', 'Email' ]" :notfound="true"/>
Пока записей нет
# Слоты
Таблицу можно сформировать с использованием слотов
<x-moonshine::table> <x-slot:thead class="text-center"> <th colspan="4">Header</th> </x-slot:thead> <x-slot:tbody> <tr> <th>1</th> <th>{{ fake()->firstName() }}</th> <th>{{ fake()->lastName() }}</th> <th>{{ fake()->safeEmail() }}</th> </tr> <tr> <th>2</th> <th>{{ fake()->firstName() }}</th> <th>{{ fake()->lastName() }}</th> <th>{{ fake()->safeEmail() }}</th> </tr> <tr> <th>3</th> <th>{{ fake()->firstName() }}</th> <th>{{ fake()->lastName() }}</th> <th>{{ fake()->safeEmail() }}</th> </tr> </x-slot:tbody> <x-slot:tfoot class="text-center"> <td colspan="4">Footer</td> </x-slot:tfoot></x-moonshine::table>
| Header | |||
|---|---|---|---|
| 1 | Carole | Nienow | qlubowitz@example.net |
| 2 | Eden | Mertz | dawn.cruickshank@example.org |
| 3 | Arnulfo | Moen | connelly.ena@example.net |
| Footer | |||
# Стилизация
Для стилизации таблицы есть предустановленные классы, которые можно использовать для tr / td
Доступные классы:
bgc-purple bgc-pink bgc-blue bgc-green bgc-yellow bgc-red bgc-gray
<x-moonshine::table> <x-slot:thead class="bgc-blue text-center"> <th colspan="3">Header</th> </x-slot:thead> <x-slot:tbody> <tr> <th class="bgc-pink">{{ fake()->firstName() }}</th> <th class="bgc-gray">{{ fake()->lastName() }}</th> <th class="bgc-purple">{{ fake()->safeEmail() }}</th> </tr> <tr> <th class="bgc-green">{{ fake()->firstName() }}</th> <th class="bgc-red">{{ fake()->lastName() }}</th> <th class="bgc-yellow">{{ fake()->safeEmail() }}</th> </tr> </x-slot:tbody></x-moonshine::table>
| Header | ||
|---|---|---|
| Camila | Satterfield | princess94@example.net |
| Randal | Waters | matilde98@example.com |