Composant Livewire de tableau de données avec recherche, tri, pagination et sélection intégrés.
|
Nom
|
Email
|
Rôle
|
Statut
|
Inscription
|
|
|---|---|---|---|---|---|
| Jean Dupont | jean@exemple.com | Admin | Actif | 12 jan. 2024 | |
| Marie Laurent | marie@exemple.com | Éditeur | Actif | 3 fév. 2024 | |
| Paul Martin | paul@exemple.com | Lecteur | Inactif | 27 fév. 2024 | |
| Sophie Bernard | sophie@exemple.com | Éditeur | Actif | 5 mars 2024 | |
| Lucas Petit | lucas@exemple.com | Admin | Actif | 18 mars 2024 | |
| Emma Rousseau | emma@exemple.com | Lecteur | Inactif | 2 avr. 2024 |
@php
$columns = [
['key' => 'name', 'label' => 'Nom', 'sortable' => true],
['key' => 'email', 'label' => 'Email', 'sortable' => true],
['key' => 'role', 'label' => 'Rôle'],
['key' => 'status', 'label' => 'Statut'],
];
$rows = [
['name' => 'Jean Dupont', 'email' => 'jean@exemple.com', 'role' => 'Admin', 'status' => 'Actif'],
['name' => 'Marie Laurent','email' => 'marie@exemple.com', 'role' => 'Éditeur', 'status' => 'Actif'],
];
@endphp
<livewire:ws::data-table
:columns="$columns"
:rows="$rows"
:searchable="true"
:selectable="true"
/>
| Prop | Type | Défaut | Description |
|---|---|---|---|
columns |
array |
[] |
Colonnes : {key, label, sortable?} |
rows |
array |
[] |
Lignes de données |
searchable |
bool |
true |
Affiche une barre de recherche |
selectable |
bool |
false |
Cases à cocher pour sélection multiple |
exportable |
bool |
false |
Bouton d'export CSV |
emptyMessage |
string |
No results found. |
Message si aucun résultat |
perPageOptions |
array |
[10, 15, 25, 50, 100] |
Options du sélecteur par page |
public function index(): View
{
return view('users.index', [
'columns' => [
['key' => 'name', 'label' => 'Nom', 'sortable' => true],
['key' => 'email', 'label' => 'Email', 'sortable' => true],
['key' => 'created_at', 'label' => 'Créé le', 'sortable' => true],
],
'rows' => User::select('id', 'name', 'email', 'created_at')
->get()
->map(fn($u) => [
'name' => $u->name,
'email' => $u->email,
'created_at' => $u->created_at->format('d/m/Y'),
])->toArray(),
]);
}
<livewire:ws::data-table
:columns="$columns"
:rows="$rows"
:searchable="true"
:selectable="true"
:exportable="true"
/>
|
Produit
|
Qté
|
Prix
|
|---|---|---|
| iPhone 15 | 12 | 999 € |
| MacBook Pro | 5 | 2 499 € |
| AirPods Pro | 24 | 279 € |
| iPad Air | 8 | 699 € |
<livewire:ws::data-table
:columns="$columns"
:rows="$rows"
:searchable="false"
/>